While(user == guillible)v2.0

Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)

Write a program that ccontinues 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.

★ Modify the program so that after 10 iterations if the user still hasn't entered 5 will tell the user "Wow, you're more patient then I am, you win." and exit.

★★ Modify the program so that it asks the user to enter any number other than the number equal to the number of times they've been asked to enter a number. (i.e on the first iteration "Please enter any number other than 0" and on the second iteration "Please enter any number other than 1"m etc. etc. The program must behave accordingly exiting when the user enters the number they were asked not to.)

I am having trouble with the last part! I can't figure out how this would work. I made the function that exits the program if they enter the number that they were asked not to enter. Also, I made a do-while loop that continues to ask the same question while the number they entered is not equal to the number that was asked not to enter. I am having trouble figuring out how the iteration would be so the program asks not to enter the number of the previous iteration. Read the example above. ^

Here is what I programmed so far:

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
30
31
32
33
// While(user == guillible)(2).cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int imput;
int WrongAnswer;

int _tmain(int argc, _TCHAR* argv[])
{
	do //Do-While loop that continues the cout statement as long as the number they imput is not equal to the number they were not asked to imput
	{
		for(int a = 0; a ++; a == WrongAnswer)
		{
		WrongAnswer --;
		cout << "Please enter any number other than " << WrongAnswer << endl;
		cin >> imput;
		}
		
		do
		{
		break;
		}
		while(imput == WrongAnswer);

	} while(imput != WrongAnswer);

	system("PAUSE");
	return 0;
}
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
while (j < 10)
{
    int number;
    cout << "enter number";
    cin >> number;
    if (number == j)
    {
        cout << "re-enter number";
        cin >> number;
    }
    j++
}


not sure if this will work, just wrote it for fun, as I am still new to C++, but if it doesn't, should give you some ideas on your path to figuring it out. I saw both your post and this looks like homework, but hopefully the above code will help you solve it.
Nice! I did something similiar. Thanks
Topic archived. No new replies allowed.