hey i have modified this game i have copied the original from my friend here is the code its working fine but when it asks for input and u input sumthing else (a-z, {,},:,",<?,!,@,#,%,^,&,)except the numbers then it becomes an infinite loop dont know whats the prob
CODE
/*Author - Manzoor.
This program uses the rand() function to
generate random numbers.*/
// Guess the number
#include <iostream>
#include <cstdlib>
#include<ctime>
using namespace std;
void play(int m); // function prototype
int main()
{
int option;
int magic;
srand(time(0));
magic = rand() % 17 + 1; // random number generator
cout << "************************\n* Welcome *\n";
cout << "* *\n* *\n* To *\n";
cout << "* *\n* *\n* Guess the Number *\n";
cout << "* *\n************************\n" << endl;
do {
cout << "\n\n[1]. Start Play\n";
cout << "[2]. Quit\n"; do {
cout << "\nEnter your choice [1 / 2]: ";
cin >> option;
if ( option == 1 ) {
cout << "\nGuess the Number between 0 - 17.\n";
cout << "\nRemember ! You only have 3 turns to guess the number.\n";
cout << "\nGood Luck !\n\n";
}
} while(option < 1 || option > 2);
switch(option) {
case 1:
magic = rand() % 17 + 1;
play(magic);
break;
case 2:
cout << "\n************************\n* GoodBye ! *\n";
cout << "* *\n* Thanks for Playing *\n";
cout << "* *\n* Made *\n";
cout << "* *\n* By *\n";
cout << "* *\n* Manzoor *\n";
cout << "* *\n************************\n\n";
break;
}
} while(option != 2);
system ("PAUSE"); // causes the program to quit after pressing a key
return 0;
}
// Play the game.
void play(int m)
{
int tries, x;
for(tries=0; tries < 3; tries++) {
cout << "\nYou have used " << tries << " turns.\n\n";
cout << "Guess the number: ";
cin >> x;
if(x == m) {
cout << "** Right **\n";
cout << "\n** You got the guess in " << tries << " guesses." << endl;
return;
}
else if(x < m) cout << "\n\nToo low.\n";
else cout << "\n\nToo high.\n";
}
cout << "\nYou have used up all your guesses.\n";
cout << "\nThe number was " << m << ".\n";
cout << "\nTry Again !" << endl;
}