From 57864ba51d6d9616168dd257d935f5210aead969 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Fri, 26 Aug 2022 15:09:27 +0100 Subject: [PATCH] Guess ranking support A^-F, number 1-100. --- main.cpp | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 4633ac8..0d73854 100644 --- a/main.cpp +++ b/main.cpp @@ -6,27 +6,28 @@ using string = std::string; void ignoreTillLineEnd(); string promptfs(string); int promptfi(string); +string guessRank(int); int main() { std::mt19937 rand {std::random_device{}()}; - std::uniform_int_distribution clamp {1, 10}; + std::uniform_int_distribution clamp {1, 100}; string name {promptfs("Enter your name:")}; std::cout << "Hello " << name << ", welcome to guess the number.\n"; - bool once {}; + int guesses {}; int num {clamp(rand)}, ent {}; do { - if (once) { + if (guesses++ > 0) { if (ent > num) std::cout << "You Guessed Too High!\n"; else std::cout << "You Guessed Too Low!\n"; } ent = promptfi("Enter your guess:"); - once = true; } while (num != ent); std::cout << "Well done " << name << ", you guessed correctly!\n"; + std::cout << "You took " << guesses << " guesses, rank " << guessRank(guesses) << " .\n"; return 0; } @@ -69,3 +70,32 @@ int promptfi(string msg) { ignoreTillLineEnd(); return toret; } + +string guessRank(int g) { + switch (g) { + case 0: + return "U"; + case 1: + return "A^"; + case 2: + return "A*"; + case 3: + return "A"; + case 4: + case 5: + return "B"; + case 6: + case 7: + return "C"; + case 8: + case 9: + case 10: + return "D"; + case 11: + case 12: + case 13: + return "E"; + default: + return "F"; + } +}