I was doing a problem on this page: http://www.cplusplus.com/forum/articles/12974/
The problem is called 'while(user == gullible)'.
I was doing this to refresh my mind about these easy things and realised i need a lot more practice than what I thought ...
Anyway, I kept trying to do this with a while stateent and it never worked but when i did it with a do-while statement it suddenly worked!?!
#include <iostream>
usingnamespace std;
int input;
int main()
{
cout << "\nPlease enter any number other than 5.";
cin >> input;
if (input == 5)
{
cout << "\nHey! You weren't supposed to do that!";
}
else
{
cout << "\nPlease enter any number other than 5.";
do
{
cin >> input;
cout << "\nPlease enter any number other than 5.";
}while(input != 5);
}
cout << "\nHey! You weren't supposed to do that!";
cin.get();
return 0;
}
This code worked, but can anyone tell me how to do this with a while statement?
This sounds like an incredibly stupid question considering i just did it with a do-while statement, but i'm sure i'm making some silly mistake.
int main()
{
int input;
cout << "\nPlease enter any number other than 5.";
cin >> input;
if (input == 5)
{
cout << "\nHey! You weren't supposed to do that!";
}
else
{
while(input != 5)
{
cout << "\nPlease enter any number other than 5.";
cin >> input;
}
cout << "\nHey! You weren't supposed to do that!";
}
cin.get();
return 0;
}