1
0

Guess the number.

This commit is contained in:
Captain ALM 2022-08-26 13:58:55 +01:00
parent a9b58871c0
commit cc4d91adf2
Signed by: alfred
GPG Key ID: 4E4ADD02609997B1

View File

@ -1,4 +1,6 @@
#include <iostream> #include <iostream>
#include <random>
#include <chrono>
using string = std::string; using string = std::string;
void ignoreTillLineEnd(); void ignoreTillLineEnd();
@ -7,15 +9,19 @@ int promptfi(string);
int main() int main()
{ {
int nameC {promptfi("Enter the number of names:")}; std::mt19937 rand {std::random_device{}()};
if (nameC < 1) { std::uniform_int_distribution clamp {1, 10};
std::cout << "No names to be entered!\n"; string name {promptfs("Enter your name:")};
return 1; std::cout << "Hello " << name << ", welcome to guess the number.\n";
bool once {};
int num {clamp(rand)}, ent {};
do {
if (once) std::cout << "You Guessed Wrong!\n";
ent = promptfi("Enter your guess:");
once = true;
} }
string* names = new string[nameC]; while (num != ent);
for (int i = 0; i < nameC; i++) names[i] = promptfs("Enter your name:"); std::cout << "Well done " << name << ", you guessed correctly!\n";
std::cout << "I have " << nameC << " to say hello to!\n";
for (int i = 0; i < nameC; i++) std::cout << "Hello " << names[i] << ".\n";
return 0; return 0;
} }
@ -24,7 +30,7 @@ void ignoreTillLineEnd() {
} }
string promptfs(string msg) { string promptfs(string msg) {
bool once {false}; bool once {};
string toret {}; string toret {};
do { do {
if (once) { if (once) {
@ -42,7 +48,7 @@ string promptfs(string msg) {
} }
int promptfi(string msg) { int promptfi(string msg) {
bool once {false}; bool once {};
int toret {}; int toret {};
do { do {
if (once) { if (once) {