Hi. I'm extremely new to this. I'm trying to do the user==gullible exercise. This is the instruction.
While( user == gullible )
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
Write a program that ccntinues to asks the user to enter any number other than 5 until the user enters the number 5.
Then tell the user "Hey! you weren't supposed to enter 5!" and exit the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include <iostream>
using namespace std;
int main()
{
int num;
cout << "Enter a number other than 5. " << endl;
cin >> num;
while (num != 5)
{
cout << "Please enter another number. " << endl;
}
cout << "I told you not to enter 5. " << endl;
return 0;
}
|
What I don't understand is when I debug this and I enter a number other than 5, it won't stop saying "Please enter another number." But, when I enter 5, it does it correctly and exits the program. What's wrong with my while loop?