From 18c5f972c245eac65a5f7a727e6c912b51e3d5ea Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Fri, 7 Oct 2022 12:35:44 +0100 Subject: [PATCH] T1 Q3 --- main.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index f25eae8..5cb069b 100644 --- a/main.cpp +++ b/main.cpp @@ -1,14 +1,30 @@ #include +#include +#include -using string = std::string; - -int main() { - std::cout << "Enter your name:\n"; - string name; - std::cin >> name; - std::cout << "Hello, " << name << "!\n"; - for (int i {0}; i < static_cast(name.size()) + 8; i++) { - std::cout << "="; +int main() +{ + using std::cout; + using std::cin; + srand(time(nullptr)); + int gcount{ 1 }; + int n { 20 }; + int secret { rand()%n + 1 }; + cout << "Guess a number between 1 and " << n << ": "; + int guess; + cin >> guess; + while (guess != secret) + { + if (guess > secret) { + cout << "Number too big ; "; + } else { + cout << "Number too small ; "; + } + gcount++; + cout << "Guess again: "; + cin >> guess; } - std::cout << "\n"; + cout << "Correct!\n"; + cout << "Took " << gcount << " tries.\n"; + return 0; }