Help with simple script

I have a little question here.

How come the script stops (takes a break or pause) and does not respond the first time the user inputs a distance.
It goes like.
---
"tell me the distance"

user choice = 2

user choice = 2

"Take a walk"
---
It seems to take a break and not respond to the first user input of distance.
Anybody knows why?

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
28
29
{
	cout << "tell me the distance" << endl;

	int dist;
	cin >> dist;

	while(!(cin>>dist)|| dist == 0)
	{
		cout << "Invalid distance input" << endl;
		cin.clear(); 
		cin.ignore(1000,'\n');
	} 

	if (dist >= 1)
	{
		if (dist < 3)
		{
			cout << "Take a walk\n" << endl;
		}
		else if (dist > 7) // om störe än 7km
		{
			cout << "Take the buss\n" << endl;
		}
		else if (dist >= 3|| dist <= 7) // mellan 2 och 8km
		{
			cout << "Take the bike\n" << endl;
		}
	}
}
You don't need cin >> dist; at line 5, because you do that on line 7.
Thanks! That was exactly what I needed help with :P
Topic archived. No new replies allowed.