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 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
int main(void)
{
using namespace std;
using std::srand;
using std::time;
using std::rand;
bool end = false;
cout<< "\t\t -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n";
cout << "\t\t+Welcome to the Guessing Game Program +\n";
cout<< "\t\t -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n\n";
while (!end)
{
int response = 0;
do
{
cout << " Main Menu\n\n";
cout << " Choose the game that you would like to play:\n";
cout << " 1)Number Guessing Game (1,2,3,4,5....)\n";
cout << " 2)Letter Guessing Game (a,b,c,d,e,f..)\n";
cout << " 3)Exit\n";
cin >> response;
}while ( response < 1 || response > 3);
if(response == 1)
{
int response = 0;
do{
cout << "NUMBER GUESSING GAME\n";
cout << "Choose Your Difficulty:\n";
cout << "1)Easy (1-5)\n";
cout << "2)Medium (1-10)\n";
cout << "3)Hard (1-20)\n";
cout << "4)Main Menu\n";
cin >> response;
}while (response < 1 || response > 4);
if (response == 1)
{
cout << "Easy Difficulty\n";
cout << "Pick a number between 1 and 5. \n \n";
cout << "You have 5 tries to get the number till game over\n";
int guess = 0;
int guessNum = 4;
int tries = 0;
srand((unsigned int)time(0));
int numPicked = rand() % 5 + 1;
for (guessNum = 4; guess != numPicked; --guessNum && tries++)
{
cout << "What would you like to guess? \n";
cin >> guess;
if(guess != numPicked)
{
cout << "\nTry again!!! \n \n";
cout << "You have " << guessNum << " tries left\n";
if(guessNum == 0)
cout << "\nYou have exceeded the number of tries GAME OVER.\n";
else if(guess == numPicked)
cout << "\nYou have guessed the number it has taken you " << tries << " tries to get he answer\n\n";
}
}
cout << "\nYou have guessed the number it has taken you " << tries << " tries to get he answer\n\n";
}
else if (response == 2)
{
cout << "This is the medium difficulty\n";
}
else if (response == 3)
{
cout << "This is the hard difficulty\n";
}
else if (response == 4)
{
cout << "Return to Main Menu\n";
}
}
else if(response == 2)
{
int response = 0;
do{
cout << "LETTER GUESSING GAME\n";
cout << "Choose Your Difficulty:\n";
cout << "1)Easy (vowels)\n";
cout << "2)Medium (consonants)\n";
cout << "3)Hard (alphabet)\n";
cout << "4)Exit\n";
cin >> response;
}while (response < 1 || response > 4);
if (response == 1)
{
cout << "Easy Difficulty\n";
cout << "Pick a vowel. \n \n";
cout << "You have 5 tries to guess the vowel till game over\n";
char arr[5] = {'a','e','i','o','u'};
int guess = 0;
int guessNum = 4;
int tries = 0;
srand(time(NULL));
random = arr[rand() % (sizeof(arr) / sizeof(arr[5]))];
for (guessNum = 4; guess != random; --guessNum && tries++)
{
cout << "What would you like to guess? \n";
cin >> guess;
if(guess != random)
{
cout << "\nTry again!!! \n \n";
cout << "You have " << guessNum << " tries left\n";
if(guessNum == 0)
cout << "\nYou have exceeded the number of tries GAME OVER.\n";
else if(guess == random)
cout << "\nYou have guessed the number it has taken you " << tries << " tries to get he answer\n\n";
}
}
cout << "\nYou have guessed the number it has taken you " << tries << " tries to get he answer\n\n";
}
else if (response == 2)
{
cout << "This is the medium difficulty\n";
}
else if (response == 3)
{
cout << "This is the hard difficulty\n";
}
else if (response == 4)
{
cout << "Return to Main Menu\n";
system("pause");
return (0);
}
}
else if (response == 3)
{
cout << "Thank you for playing this game\n";
system("pause");
return (0);
}
}
system("pause");
return (0);
}
| |