1
0

Guess ranking support A^-F, number 1-100.

This commit is contained in:
Captain ALM 2022-08-26 15:09:27 +01:00
parent 9fae0e4409
commit 57864ba51d
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -6,27 +6,28 @@ using string = std::string;
void ignoreTillLineEnd(); void ignoreTillLineEnd();
string promptfs(string); string promptfs(string);
int promptfi(string); int promptfi(string);
string guessRank(int);
int main() int main()
{ {
std::mt19937 rand {std::random_device{}()}; 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:")}; string name {promptfs("Enter your name:")};
std::cout << "Hello " << name << ", welcome to guess the number.\n"; std::cout << "Hello " << name << ", welcome to guess the number.\n";
bool once {}; int guesses {};
int num {clamp(rand)}, ent {}; int num {clamp(rand)}, ent {};
do { do {
if (once) { if (guesses++ > 0) {
if (ent > num) if (ent > num)
std::cout << "You Guessed Too High!\n"; std::cout << "You Guessed Too High!\n";
else else
std::cout << "You Guessed Too Low!\n"; std::cout << "You Guessed Too Low!\n";
} }
ent = promptfi("Enter your guess:"); ent = promptfi("Enter your guess:");
once = true;
} }
while (num != ent); while (num != ent);
std::cout << "Well done " << name << ", you guessed correctly!\n"; std::cout << "Well done " << name << ", you guessed correctly!\n";
std::cout << "You took " << guesses << " guesses, rank " << guessRank(guesses) << " .\n";
return 0; return 0;
} }
@ -69,3 +70,32 @@ int promptfi(string msg) {
ignoreTillLineEnd(); ignoreTillLineEnd();
return toret; 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";
}
}