Not sure if I'm heading in the right direction. I just attempted to do the first part, I found this article here on the forums for beginners and I'm giving it a shot. I am also not sure how to approach the second part or third part.
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 ask the user to enter any number other than 5 until the user enters the number 5. Then tell the user "Hey, you weren't suppose to enter 5!" and exit the program.
* Modify the program so that after 10 iterations if the user still hasn't entered 5 it 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" 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 16 17 18 19 20 21 22 23
|
#include <iostream>
using namespace std;
int main() {
int num;
do{
cout << "Enter any number other than 5." << endl;
cin >> num;
}while(num!=5);
if(num !=5)
{
cout << "Good job!" << endl;
}
else
cout << "Hey you weren't suppose to enter 5!" << endl;
return 0;
}
|