-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuessing_Game.cpp
56 lines (44 loc) · 1.07 KB
/
Guessing_Game.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
#include <iostream>
using namespace std;
int guessCorrect(char);
int alphabetRandom();
const int MAX = 26;
int main(void)
{
char letter;
int guess_count = 26;
while(guess_count != 0)
{
cout << "\nEnter The Guessing letter: ";
cin >> letter;
if(guessCorrect(letter))
{
cout << "\nYour Answer Was correct !";
break;
}
else
cout << "\nSorry Your answer was incorrect !";
guess_count--;
cout << "\nThe Number of Guess: " << guess_count;
}
}
int guessCorrect(char guess)
{
bool True = 1, False = 0;
if(alphabetRandom() == guess)
return True;
return False;
}
int alphabetRandom()
{
char alphabet[MAX] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z'
};
char res;
for(int i = 0; i < 2; i++)
res = alphabet[rand() % MAX];
return res;
}