C++ Practice question
Hey everyone! Im working on this practice problem: 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.) So far I have everything operational until the two star. When I run the program it stops after 10 loops and the number not to enter increases by one each time but even if you enter the number it does not end. Here is my code not sure why it is not working. Thanks for help! #include <iostream> using namespace std; int main() { int x; int y = 0; int run = 1; while ((x != y) && (run <=10)) { cout << "Please enter a number other than " << y << endl; cin >> x; ++run; y++; } if (x == y) { cout << "You lose" << endl; } else { cout << "You win" << endl; } return 0; }