//A Game that has you guess a random number //Created by Gilad "Speaker For The Dead" Barlev //Final Programming Edit on 26/11/01 (D/M/Y) //Final Internal Documentation Edit on 15/11/01 (D/M/Y) #include #include #include using namespace std; int main () {//beginning of main program //intro cout << "Speaker For The Dead Presents..." << endl << endl; getch (); //initialize random seed srand(time(NULL)); //declare variables int mode = 0; int modeb = 0; int range = 0; int num = 0; int guess = 0; int guesses = 0; //main menu Main: cout << "High" << endl << endl << " Low" << endl; getch (); cout << endl << endl << "Select mode:" << endl << "(1) Practice" << endl << "(2) Game" << endl << "Enter any other value to quit" << endl << "?"; cin >> mode; if (mode == 1) {//practice mode //practice setup cout << endl << "PRACTICE:" << endl; getch (); cout << endl << "Select range of practice: (1-?)" << endl << "Enter 0 to goto Main Menu" << endl << "? "; cin >> range; if (range < 1) {//quit to main menu goto Main; }//end of quit //reset guess count and initialize random number guesses = 0; num = 1 + rand () % (range); while (num != guess) {//main practice cout << "Guess=? "; cin >> guess; guesses = guesses + 1; if (num > guess) {//too low cout << "TOO LOW!!" << endl; }//end of too low if (num < guess) {//too high cout << "TOO HIGH!!" << endl; }//end of too high }//end of main practice //victory statement cout << "YOU GOT IT IN " << guesses << " GUESSES!!!" << endl; getch(); //return to main menu goto Main; }//end of practice mode if (mode == 2) {//game mode //game main menu cout << "THE GAME" << endl << endl << "(1) Rules" << endl << "(2) Play" << endl << "(3) Go to Main Menu" << endl << "?"; cin >> modeb; if (modeb != 1 && modeb != 2) {//quit to main menu goto Main; }//end of quit if (modeb == 1) {//rules cout << endl << endl << "You have ten chances to guess a number bewteen 1 and x." << endl << "There are five levels." << endl << "The game will tell you the number of the guess" << endl << "and whether your last guess was too high or too low." << endl << "Good luck." << endl; getch (); modeb = modeb + 1; }//end of rules if (modeb == 2) {//game //reset level counter int lvl = 0; while (lvl < 5) {//level loop lvl = lvl + 1; guesses = 0; //initialize range if (lvl == 1) {//lvl 1 range initialization range = 100; }//end of lvl 1 range if (lvl == 2) {//lvl 2 range initialization range = 200; }//end of lvl 1 range if (lvl == 3) {//lvl 3 range initialization range = 300; }//end of lvl 1 range if (lvl == 4) {//lvl 4 range initialization range = 500; }//end of lvl 1 range if (lvl == 5) {//lvl 5 range initialization range = 1000; }//end of lvl 1 range //reset guess count and initialize random number num = 1 + rand () % (range); //display level and range cout << "Level " << lvl << endl << "I'm thinking of a number between 1 and " << range << endl << "Guess it." << endl; while (num != guess && guesses < 10) {//main game guesses = guesses + 1; cout << guesses << endl << "Guess=? "; cin >> guess; if (num > guess) {//too low cout << "TOO LOW!!" << endl; }//end of too low if (num < guess) {//too high cout << "TOO HIGH!!" << endl; }//end of too high }//end of main game if (guesses > 9 && num != guess) {//defeat statement cout << endl << "GAME OVER" << endl << "The number was " << num << endl; goto Credits; }//end defeat //victory statement cout << "YOU GOT IT IN " << guesses << " GUESSES!!!" << endl; getch(); }//end of level loop //ultimate victory statement cout << endl << "CONGRATULATIONS!!!" << endl << "You Beat The Game!" << endl; getch (); //return to main menu goto Main; }//end of game }//end of game mode Credits: //credits and return function cout << "This program was made by Speaker For The Dead for entertainment purposes only." << endl << "For problems with this program or more information on Speaker For The Dead," << endl<< "Please send an email to the_sftd@yahoo.com" << endl; return 0; }//end of program //This program was made by Speaker For The Dead for entertainment purposes only. //For problems with this program or more information on Speaker For The Dead, //Please send an email to the_sftd@yahoo.com