Adding a counter

How do I make this so if the user does not enter the number 5 10 times in a row it will display something like "You pay to directions well".

I just can't seem to think of where to start with it. I thought a for loop but I didn't know exactly where to do with it

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 int main()
{
	int x = 0;
	
	{
		//ask user to enter a number except for 5, if number is not 5 keep asking

		cout << "Please enter a number other than 5." << endl;
		cin >> x;

		do
		{
			cout << "Please enter a number other than 5." << endl;
			cin >> x;
		} while (x != 5);

		// if the user enters 5, cout "Hey! you weren't supposed to enter 5!"

		if (x == 5)
		{
			cout << "Hey! You weren't suppose to enter the number 5!" << endl;
		}
}
do this
1
2
3
4
5
6
7
8
9
int tries=0;
                do
		{
			cout << "Please enter a number other than 5." << endl;
			cin >> x;
                        ++tries
                        if (tries == 10)
                        cout << "You pay to directions well" << endl;
		} while (x != 5);
Last edited on
Topic archived. No new replies allowed.