The goal for this project was to:
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.
Requires:
- variables, data types, and numerical operators
- basic input/output
- logic (
ifstatements,switchstatements)- loops (
for,while,do-while)
(I'm not doing the 2 stars one yet)
My questions are:
- How can I optimize my code in every possible way? (efficiency, readability, etc)
- How can I improve the code syntax?
#include <iostream> using std::cout; using std::cin; int main() { int UserNumber = 0; int k = 1; while (k < 11) { cout << "\nEnter any number other than 5: "; cin >> UserNumber; if (UserNumber == 5) { cout << "\n\n\nHey! You weren't supposed to enter 5!\n\n\n"; exit(0); } else if (k == 10) { cout << "Wow, you're more patient then I am, you win.\n\n\n"; exit(0); } k++; } }