I was just wondering is this a good way of writing the code for this exercise:
While( user == gullible )
Requires:
variables, data types, and numerical operators
basic input/output
logic (if statements, switch statements)
loops (for, while, do-while)
Write a program that continues 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.)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
int num = 0;
int count = 0;
while (num != -99)
{
cout << "Please enter a number other then " << count << ':';
cin >> num;
if (num == count){
cout << "You were not suppose to enter that number!\n";
break;
}
count++;
}
|
I dont really like how i used the while (num!= -99) in order to run the loop. Is there a better way of doing this?