Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

FILL IN THE QUESTION MARKS #include using namespace std; // be sure to add any #

ID: 644661 • Letter: F

Question

 FILL IN THE QUESTION MARKS #include  using namespace std;  // be sure to add any #include directives that yuo may need ???  //-------------------------------------------------------------------------------------------------- // FUNCTION: int GetRangeMaximum() // // Promts the user to enter an integer value between 10 and 1000 (inclusive). // // if the user enters a number that is not valid, // then display an error message and ask again. // // if the user enters a valid choice, // then return that value. // //--------------------------------------------------------------------------------------------------  ???  //-------------------------------------------------------------------------------------------------- // FUNCTION: int GetSecretNumber(int min, int max) // // Generates and returns a "random" number between min value and max value (inclusive). // //--------------------------------------------------------------------------------------------------  ???  //-------------------------------------------------------------------------------------------------- // FUNCTION: int GetNumberOfAttemptsAllowed() // // Prompts the user to enter the number of attemts that they will have to guess the secret number. // This value must be in the range of 10 to 100 (inclusive) // // if the user enters a number that is not a valid, // then display an error message and ask again. // // if the user enters a valid number, then return that value. // //--------------------------------------------------------------------------------------------------  ???  //-------------------------------------------------------------------------------------------------- // FUNCTION: int GetUsersGuess() // // Prompts the user to enter their guess. // Then return that value. // //--------------------------------------------------------------------------------------------------  ???  //-------------------------------------------------------------------------------------------------- // FUNCTION: int GiveFeedback(int usersGuess, int secretNumber) // // Gives user feedback based on thier guess. // // if the user's guess is the same as the secret number then diplay "CORRECT!". // if the user's guess is less than the secret number then diplay "TOO LOW!". // if the user's guess is greater than the secret number then diplay "TOO HIGH!". // //--------------------------------------------------------------------------------------------------  ???  //-------------------------------------------------------------------------------------------------- // FUNCTION: bool AskUserIfTheyWillPalyAgain() // // Asks the user if they would like to play again. // // if they answer "yes" then return true; // if they answer "no" then return false; // if they give an aswer other than "yes" or "no" then ask again. // //--------------------------------------------------------------------------------------------------  ???   // this main function is complete and should not require any modifications int main() {         int secretNumber = 0, usersGuess = 0;         int numberOfAttemptsAllowed = 0, numberOfGuessesUsed = 0;         int max = 0;         bool playAgain = true;          do         {                 max = GetRangeMaximum();                 secretNumber = GetSecretNumber(1, max);                 numberOfAttemptsAllowed = GetNumberOfAttemptsAllowed();                  do                 {                         usersGuess = GetUsersGuess();                         numberOfGuessesUsed++;                         GiveFeedback(usersGuess, secretNumber);                 } while (usersGuess != secretNumber && numberOfGuessesUsed < numberOfAttemptsAllowed);                   playAgain = AskUserIfTheyWillPalyAgain();         } while (playAgain);          return 0; } 

Explanation / Answer

#include <iostream>
using namespace std;

// be sure to add any #include directives that yuo may need

#include <string>
#include <ctime>
#include <cstdlib>

//--------------------------------------------------------------------------------------------------
// FUNCTION: int GetRangeMaximum()
//
// Promts the user to enter an integer value between 10 and 1000 (inclusive).
//
// if the user enters a number that is not valid,
// then display an error message and ask again.
//
// if the user enters a valid choice,
// then return that value.
//
//--------------------------------------------------------------------------------------------------

int GetRangeMaximum(){
   int value;
   cout << "For maximum value" << endl;
   cout << "enter an integer value between 10 and 1000 (inclusive): ";
   cin >> value;
   while(value > 1000 || value < 10){
       cout << "Number is invalid. Try again: ";
       cin >> value;
   }
   return value;
}

//--------------------------------------------------------------------------------------------------
// FUNCTION: int GetSecretNumber(int min, int max)
//
// Generates and returns a "random" number between min value and max value (inclusive).
//
//--------------------------------------------------------------------------------------------------

int GetSecretNumber(int min, int max){
   srand(time(NULL));
   return (rand() % (max - min + 1))+ min;
}

//--------------------------------------------------------------------------------------------------
// FUNCTION: int GetNumberOfAttemptsAllowed()
//
// Prompts the user to enter the number of attemts that they will have to guess the secret number.
// This value must be in the range of 10 to 100 (inclusive)
//
// if the user enters a number that is not a valid,
// then display an error message and ask again.
//
// if the user enters a valid number, then return that value.
//
//--------------------------------------------------------------------------------------------------

int GetNumberOfAttemptsAllowed(){
   int value;
   cout << "For number of attempts" << endl;
   cout << "enter an integer value between 10 and 100 (inclusive): ";
   cin >> value;
   while(value > 100 || value < 10){
       cout << "Number is invalid. Try again: ";
       cin >> value;
   }
   return value;
}

//--------------------------------------------------------------------------------------------------
// FUNCTION: int GetUsersGuess()
//
// Prompts the user to enter their guess.
// Then return that value.
//
//--------------------------------------------------------------------------------------------------

int GetUsersGuess(){
   int value;
   cout << "Enter your guess: ";
   cin >> value;
   return value;
}

//--------------------------------------------------------------------------------------------------
// FUNCTION: int GiveFeedback(int usersGuess, int secretNumber)
//
// Gives user feedback based on thier guess.
//
// if the user's guess is the same as the secret number then diplay "CORRECT!".
// if the user's guess is less than the secret number then diplay "TOO LOW!".
// if the user's guess is greater than the secret number then diplay "TOO HIGH!".
//
//--------------------------------------------------------------------------------------------------

int GiveFeedback(int usersGuess, int secretNumber){
   if(usersGuess == secretNumber){
       cout << "CORRECT!" << endl;
   }
   else if(usersGuess < secretNumber){
       cout << "TOO LOW!" << endl;
   }
   else{
       cout << "TOO HIGH!" << endl;
   }
}

//--------------------------------------------------------------------------------------------------
// FUNCTION: bool AskUserIfTheyWillPalyAgain()
//
// Asks the user if they would like to play again.
//
// if they answer "yes" then return true;
// if they answer "no" then return false;
// if they give an aswer other than "yes" or "no" then ask again.
//
//--------------------------------------------------------------------------------------------------

bool AskUserIfTheyWillPalyAgain(){
   string choice;
   cout << "would you like to play again? ";
   cin >> choice;
   while(choice != "yes" && choice != "no"){
       cout << "Invalid choice. Try again: ";
       cin >> choice;
   }
   if(choice == "yes"){
       return true;
   }
   else{
       return false;
   }
}


// this main function is complete and should not require any modifications
int main()
{
        int secretNumber = 0, usersGuess = 0;
        int numberOfAttemptsAllowed = 0, numberOfGuessesUsed = 0;
        int max = 0;
        bool playAgain = true;

        do
        {
                max = GetRangeMaximum();
                secretNumber = GetSecretNumber(1, max);
                numberOfAttemptsAllowed = GetNumberOfAttemptsAllowed();

                do
                {
                        usersGuess = GetUsersGuess();
                        numberOfGuessesUsed++;
                        GiveFeedback(usersGuess, secretNumber);
                } while (usersGuess != secretNumber && numberOfGuessesUsed < numberOfAttemptsAllowed);


                playAgain = AskUserIfTheyWillPalyAgain();
        } while (playAgain);

        return 0;
}