-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
78 lines (74 loc) · 1.39 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<iostream>
#include<random>
#include<ctime>
#include<string>
using namespace std;
int getRandomNumber()
{
mt19937 mersenne{static_cast<mt19937::result_type>(time(nullptr))};
uniform_int_distribution<> die{1,100};
return die(mersenne);
}
string checkRandom(int main_num, int random_num)
{
if(main_num>random_num)
{
return "Your guess is high\n" ;
}
if(main_num<random_num)
{
return "Your guess is low\n";
}
if(main_num==random_num)
{
return "Correct\n";
}
}
int retry()
{
cout << "Would you like to retry[y/n]";
char check;
cin >> check;
if(check=='y')
{
return true;
}
else if (check=='n')
{
return false;
}
else
{
retry();
}
{
return false;
}
}
int main()
{
cout << "Lets Play a Game. I'm thinking of a number.\n";
int main_num{0};
int counter{0};
int random_num{getRandomNumber()};
while(true)
{
++counter;
cout << "Guess: #" << counter << '\t';
cin >> main_num;
string result{checkRandom(main_num,random_num)};
cout << result;
if(result=="Correct\n")
{
if(retry())
{
main();
}
else
{
cout << "Thanks for playing.";
return 0;
}
}
}
}