-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguessingGame.cpp
103 lines (89 loc) · 2.39 KB
/
guessingGame.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <cstdlib>
#include <string.h>
#include <time.h>
#include<bits/stdc++.h>
using namespace std;
int main(){
start:
int index,chances;
string word = "";
string hiddenWord="";
string letter;
char next;
string names[] = {"aela", "evan", "aidan", "keanna", "kaylan", "ava", "mireille"};
string countries[] = {"Rwanda", "burundi", "kenya", "tanzania", "congo", "Sudan", "America"};
string colors[] = {"Red", "White", "Blue", "Yellow", "Black", "purple", "Violet"};
string animals[] = {"pig", "cow", "cat", "sheep", "goat", "rat", "gorilla"};
string categories[] = {"names", "countries", "colors", "animals"};
cout << "--------------WELCOME TO THE GUESSING GAME------------------ \n \n \n";
//display and choose category
for(int i = 0; i <(sizeof(categories) / sizeof(*categories)); i++){
cout << "\t"<< i + 1 << "." << categories[i] << endl;
}
cout << "Please select the category(eg : 1 for names): ";
cin >> index;
// choose a random word;
srand(time(0));
int chosen = rand() % 6;
switch(index){
case 1:
word = names[chosen];
break;
case 2:
word = countries[chosen];
break;
case 3:
word = colors[chosen];
break;
case 4:
word = animals[chosen];
}
chances = word.length() - 1;
for(int i = 0; i<word.length(); i++){
hiddenWord.replace(i,1, "-");
}
//choose a letter of the alphabet
int k = 5;
while(k > 0){
transform(word.begin(), word.end(), word.begin(), ::tolower);
if(hiddenWord.compare(word) == 0){
break;
}
cout << "\n \n -Choose any letter of the alphabet: " << endl;
cin >> letter;
if(letter.compare("exit") == 0){
exit(0);
}
for(int i = 0; i < word.length(); i++) {
if(tolower(word[i])== letter[0]){
hiddenWord[i] = letter[0];
}
}
for(int i = 0; i < hiddenWord.length(); i++){
if(hiddenWord[i]){
cout << hiddenWord[i];
}else{
cout << "-";
}
}
cout << endl << "===" << k << " trials remaining"<<"===";
k--;
}
for(int i=0; i < hiddenWord.length() ;i++){
if(hiddenWord[i] == '-'){
cout << "\n ===========YOU LOSE=========";
goto terminate;
}
}
cout << "\n \n------- OUUU!! YOU WIN!!---------";
terminate:
cout << "\n Do you want to restart? (y/n): ";
cin >> next;
if(next == 'y'){
goto start;
}else{
exit(0);
}
return 0;
}