-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathe8.cpp
68 lines (60 loc) · 1.02 KB
/
e8.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
#include "../std_lib_facilities.h"
int main ()
{
vector<string> secret;
vector<string> guess;
srand(time(nullptr));
for (int i {0} ; i < 4 ; ++i)
{
string s= to_string(char('a' + rand() % 26));
secret.push_back(s);
}
int bulls {0};
int cows {0};
int count {0};
while (bulls != 4)
{
bulls = 0;
cows = 0;
cout << "Enter four numbers letter from a to z (0 to quit): " << endl;
for (string input ; cin >> input ;)
{
if (input == "0" || input.size() > 1 && input != "cheat")
{
cerr << "Error";
exit(EXIT_SUCCESS);
}
else if (input == "cheat")
{
for (const auto &s: secret)
{
cout << s << " ";
}
cout << endl;
}
else
{
guess.push_back(input);
}
if (guess.size() == 4)
{
break;
}
}
for (int i {0} ; i != guess.size() ; ++i)
{
if (guess[i] == secret[i])
{
++bulls;
}
else
{
++cows;
}
}
cout << "Bulls: " << bulls << " Cows: " << cows << endl;
++count;
guess.clear();
}
cout << "You finished in " << count << " Tries." << endl;
}