Why cant I use while statements!!!

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!?!

Here is the code:

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
#include <iostream>

using namespace 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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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;
}
Wow...

Im sorry i couldn't spot that.

I am ashamed of myself.
Topic archived. No new replies allowed.