Answer to Question #99440 in C++ for Caleb

Question #99440
Using a conditional expression, write a statement that increments numUsers if updateDirection is 1, otherwise decrements numUsers. Ex: if numUsers is 8 and updateDirection is 1, numUsers becomes 9; if updateDirection is 0, numUsers becomes 7.

Hint: Start with "numUsers = ...".
#include <iostream>
using namespace std;

int main() {
int numUsers;
int updateDirection;

cin >> numUsers;
cin >> updateDirection;

/* Your solution goes here */

cout << "New value is: " << numUsers << endl;

return 0;
}
1
Expert's answer
2019-12-02T12:16:29-0500
numUsers = (updateDirection == 1) ? numUsers + 1 : numUsers - 1;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS