Salutations!
I'm basically trying to go through all of the beginning problems that were posted here:
http://www.cplusplus.com/forum/articles/12974/
The output i'm trying to achieve is:
Enter a number:
5
Enter a number as long as it is not 5.
6
Enter a number as long as it is not 6.
6
Congrats! you win!
However, the output I get is:
Enter a number:
5
Enter a number as long as it is not 5:
4
Congrats! You win!
I figured if I used one variable, then I would basically just have it repeat as long as it is not equal to itself. Sadly, the output does not match up. So I don't understand why it doesn't work.
IF any of you are able to explain why it doesn't work or have anywhere I can look, then I would greatly appreciate it.
This is my first post on this site so if you have any criticism then please tell me so I may better myself.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
// a revised while(user==gullible) program where they are asked to
// input a number first and then another number that is different than the one before,
// if they input the number the inputted before then they win.
#include <iostream>
using namespace std;
int main()
{
int x;
cout << "Enter a number. " << endl;
cin >> x;
do
{
cout << "Enter another number as long as it is not " << x << "." << endl;
cin >> x;
} while (x != x);
cout << "Congrats! You win! " << endl;
return 0;
}
|