Need help!

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++.
What does "you do something" mean? And what does "the variable either goes up or down" mean?
If someone chose option "A" the variable will go up 1.
If someone chose option "B" the variable will go down 1.
It depends on what the user chooses.
And what is the problem?
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.
So what?
Last edited on
How do I have the variable never touch 1. That's my problem.
Have you invested into a switch?
Sounds to me like
initialize variable
loop
-input
-change variable
--if variable is equal to 1 change again
-restart loop
quit program
I have not, and this sounds like my solution. Thank you!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
int theVariable = 0;
char c;


do
{
   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 ) )
   {
      case 'A':
         theVariable += 1 + !theVariable;
         break;

      case 'B':
         theVariable -= 1 + ( theVariable == 2 );
         break;
   }
} while ( c != 'Q' );
Last edited on
Topic archived. No new replies allowed.