// --------------------------------------------------------------------------- // BestGuess.cpp // // Written By: YourNameGoesHere // Last Modified: DueDateGoesHere // // Description: // Delete this and // Write something appropriate here that describes what the program does // --------------------------------------------------------------------------- XXXXXXX // include iostream to be able to use std::cin and std::cout XXXXXXX // include cstdlib for use of srand() and rand() functions XXXXXXX // include ctime for use of time() function YYYYYYYYY // make use of the appropriate namespace for cin and cout // --------------------------------------------------------------------------- // Declare global function prototypes to be used by main() function // --------------------------------------------------------------------------- int GetGuess(); int CalcRelation(int guess, int secretNum); // --------------------------------------------------------------------------- // Declare and define global constants // --------------------------------------------------------------------------- const int QUIT_REQUEST = ZZZZ; // declare and define QUIT_REQUEST as a const int with value -999 // --------------------------------------------------------------------------- // main() --- it all begins here // --------------------------------------------------------------------------- int main() { // Setup - Seed the random number generator XXXXXXXXXXX // Setup - Init secretNumber = some random number from 1 to 100, // and Init other local vars: tries = 0, guess = 0, relation = QUIT_REQUEST // TODO: multiple lines missing here XXXXXXXX // Setup - Offer initial welcome screen with directions cout << "Welcome to Best Guess!!!\n\n"; cout << "I have selected a number from 1 to 100.\n"; cout << "Try to guess it.\n\n"; // Create the Game Loop do { // Call a function to ask the user for a number and return it // Store the result in the local variable named: guess guess = XXXXXX // Increment local variable: tries XXXXXX // Call a function // that takes the guess and secretNumber as parameters // that returns -1 for too low, 1 for too high, 0 for match, // and const value: QUIT_REQUEST for quit (i.e. guess <= 0) // Store the return value in local variable named: relation XXXXXXX // Process the value of the variable relation accordingly // Use a switch statement as outlined based on // the value of local variable named: relation switch (XXXXXXXXX) { case QUIT_REQUEST: cout << "You want to quit... awwwww but why?\n"; cout << "See you later.\n"; break; case XXXXXXXX: cout << "Too High. Try again\n"; break; XXXXXXXX cout << "Too Low. Try again\n"; break; XXXXXXXXX cout << "\nAmazing! How did you know?\n"; cout << "You got it in " << YYYYYYY << " guesses.\n"; XXXXXXXXXX XXXXXXXX: cout <<"\nERROR --- relation == " << relation << endl; } // end switch } while ( (relation != XXXXXXXX) && (relation != XXXXXXXXX) ); XXXXXXXXX // return 0 to indicate success to the operating system } // end main() // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // Definition of Global Functions follows // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // --------------------------------------------------------------------------- // GetGuess // Asks the user for a number and returns it // Also indicates that a guess of zero will quit out of the game // --------------------------------------------------------------------------- XXXXXXX GetGuess() { int guess; cout << "What number do you guess (0 to quit): "; XXXXXXXX return guess; } // --------------------------------------------------------------------------- // CalcRelation // Takes integers: guess and secretNum as input parameters // Returns -1 for too low, 1 for too high, 0 for match, // and const value: QUIT_REQUEST for quit // quit will be triggered if gues is <= 0 // --------------------------------------------------------------------------- XXXXXXXX CalcRelation(XXXXXXXX, YYYYYYYYYY) { int retVal = XXXXXXX; // default retVal to QUIT_REQUEST if (guess <= 0) { retVal = QUIT_REQUEST; } else if (XXXXXXXXXX) { XXXXXX // 1 for too high } else if (XXXXXXXXXXX) { XXXXXXXX // negative 1 for too low } else { XXXXXXXX // zero for match } return retVal; } // end file