I'm doing this project for class and it requires that the variable never hits 1. The variable also either goes up by 1, or down by 1 every time you do something.
So for example it can go :
-2 -1 0 2 3 4 . . .
I have no idea how to make that work. Please help!
Also I'mm using C++.
The variable can never be the number 1. Never. So if the variable is 0 at the moment, and I chose option "A" it has to go to 2, if I do it again it goes to 3. Now, if I chose option "B" it has to go to 2, again, it has to go back 0.
int theVariable = 0;
std::cout << "Variable is equal to " << theVariable << std::endl << std::endl;
std::cout << "Enter A to increase the variable, B to decrease it or Q to quit: ";
std::cin > c;
switch ( toupper( c ) )
theVariable += 1 + !theVariable;
theVariable -= 1 + ( theVariable == 2 );
} while ( c != 'Q' );