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

Using the code below, analyze the strategy of guessing from at least three diffe

ID: 668016 • Letter: U

Question

Using the code below, analyze the strategy of guessing from at least three different users and compare them in a few paragraphs. How does this strategy work within the algorithm you developed? What would you change within your algorithm or code to make the game easier or harder, based on this information?

// CS5123 Adv. Programming and Data Structures
// Fall 2015
// Project 1, Part 1: Number Guessing Game
// by Alhaji S. Conteh
// Date: 9/1/2015
// File: part1.cpp

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

//macros to define the range and number of guesses
#define MAX_RANGE 100
#define MAX_GUESSES 10

using namespace std;

//main function
int main(){

//to generate continuous random numbers
   while (true){
       srand(time(NULL));

       //declare the variables
       int secretNumber = rand() % MAX_RANGE + 1;
       int countOfGuesses = 0;
       int yourGuess = 0;
       cout << " Welcome to the guessing game!!!" << endl;
       cout << " You have 10 attempts to guess the secret number" << endl;

//loop to play the game
       while (countOfGuesses < MAX_GUESSES ) {

           //prompt the user to guess the number
           cout << " Enter a number in the range of 1-100: ";
           cin >> yourGuess;
           countOfGuesses++;

           //condition whether the user's guess is low, high, or correct.
           if (yourGuess < secretNumber){
               cout << " Your guess is lower than the secret number" << endl;
               cout << " You still have " << MAX_GUESSES - countOfGuesses << " attempts left. " << endl;
           }
           else if (yourGuess > secretNumber){
               cout << " Your guess is higher than the secret number" << endl;
               cout << " You still have " << MAX_GUESSES - countOfGuesses << " attempts left. " << endl;
           }
           //if the user guesses the secret number then print the below block details
           else{
               cout << " Congratulations!!! You guessed the secret number correct" << endl;
               cout << " The secret number is: " << secretNumber << endl;
               cout << " You took " << countOfGuesses << " attempts to guess the number correct "<< endl;
               break;
           }
       }

//if user exceeds the maximum guesses then print the below block details
       if (countOfGuesses == MAX_GUESSES){
           cout << " Sorry. You have already made " << MAX_GUESSES << " number of guesses" << endl;
       }

       //while loop to continue playing the game
       char input;
       while (true) {

           cout << " Would you like to play again (Y/N)? ";
           cin >> input;

           if (input == 'n' || input == 'N' || input == 'y' || input == 'Y') {
               break;
           }
           else {
               cout << " Please enter 'Y' or 'N'... ";
           }
       }

       if (input == 'n' || input == 'N') {
           std::cout << " Program terminated";
           break;
       }
       else {
           std::cout << " ";
       }
   }


       return 0;
}

Explanation / Answer

The strategy is that it will randomly pick a number from 1 to 100.
The strategy is that you start from number 50 and then check the message and based on that continue with the search.
if it is in upper half then take 75 as the next guess and based on that continue.

you can make the game easier with the above approach.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote