Question

Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...

Lab #6 Number Guessing Game – Loops and Nested Loops
Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, allow the user to try up to 10 times to guess the number, and tell the user if each guess is too high, too low, or correct.
The actual game portion must be a function...you can use more than one function in your program.
The amount of time spent designing the program before hand is directly related to the time spent writing and debugging the program.
The program will:
1. Compute a unique random number using the random number generator and time as a seed 2. Announce the game and rules to the user at each “start” of a new game 3. Allow the user 10 tries to guess the number. For each guess: a. If it is correct announce to the user that they won, then ask if they want to play again b. If it is incorrect i. Tell the user whether the number they guessed is too high or too low ii. Tell the user how many guesses they have remaining iii. If it is the tenth attempt, tell the user the games is over and ask if they want to play again 4. Once the game is over (win or lose), ask the user if the would like to play again and handle each condition.
Lab references:
Random number generator page 128 (Gaddis)
Loops – Chapter 5 (Gaddis)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

void displayRules();
void playGuessingGame();
bool playAgain();
int main()
{
  
//Setting the seed value
srand(2);


while(true)
{
displayRules();
playGuessingGame();
bool b=playAgain();
if(b)
{
   continue;
   }
   else
   {
       break;
   }

}

  
return 0;
}
void displayRules()
{
   cout << "\nYou must guess my number (it is between 1 and 100)" << endl;
cout << " You have a maximum of 10 tries to guess my number OK," << endl;

}
void playGuessingGame()
{
   // Declaring variables
int userGuess;
char ch;
  
int no_of_attempts = 0, maxAttempts = 10;
  
   int randomNumber = rand() % 100 + 1;



while (maxAttempts > 0)
{
cout << "\nEnter Your Guess:";
cin >> userGuess;
if (userGuess > randomNumber)
{
cout << "You guess is Too High." << endl;
cout << " You have " << --maxAttempts << " attempts left" << endl;
}
else if (userGuess < randomNumber)
{
cout << "You guess is Too Low." << endl;
cout << " You have " << --maxAttempts << " attempts left" << endl;
}
else if (userGuess == randomNumber)
{
  
cout << "Correct!"<< endl;
break;
}
if (maxAttempts == 0)
{
   cout<<"Game Over!"<<endl;
cout << "The Number is :"<<randomNumber << endl;
}
}

}

bool playAgain()
{
   char ch;
  
   // Prompting the user to play again or not
cout << "\nDo you want to Play again(y/n):";
cin >> ch;
if (ch == 'y' || ch == 'Y')
{
return 1;
}
else
{
return 0;
}
  
}

_________________________

Output:

C:Program Files (x86)\Dev-Cpp MinGW64\bin\GuessingGameBetween0To100In!0Attempts.exe ou must guess my number (it is between 1

i. C:\Program Files (x86)\Dev-Cpp\MinGw64\bin\GuessingGameBetweenOTo 1001nOAttempts.exe ou must guess my number (it is betwee


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Lab #6 Number Guessing Game – Loops and Nested Loops Requirements: Design, develop, test, and submit a program for a Number Guessing game. The program will select a random number between 0 and 100, al...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This program will implement a simple guessing game... Write a program that will generate a random...

    This program will implement a simple guessing game... Write a program that will generate a random number between 1 and 50 and then have the user guess the number. The program should tell the user whether they have guessed too high or too low and allow them to continue to guess until they get the number or enter a 0 to quit. When they guess the number it should tell them how many guesses it took. At the end, the...

  • Write a JAVA program that plays a number guessing game with the user. A sample run...

    Write a JAVA program that plays a number guessing game with the user. A sample run for the game follows. User input is shown in boldface in the sample run. Welcome to the game of Guess It! I will choose a number between 1 and 100. You will try to guess that number. If your guess wrong, I will tell you if you guessed too high or too low. You have 6 tries to get the number. OK, I am...

  • Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts...

    Write a game application that generates a random number between 1 and 1000 (inclusive) and prompts the user for a guess. Use the pseudorandom number generator, the Random class. When the user guesses the correct number, say so, and display how many guesses the user required to guess correctly. Allow the user to play multiple times by asking the user if the user wants to continue playing.      Guess my number between 1 and 1000 => 500      Too high...

  • Please write a C# program that where a player will play a guessing game with the...

    Please write a C# program that where a player will play a guessing game with the range of 1-100. Each time the play guesses a number, and it is not correct the program should indicate if the number is more or less than what the player guessed. The play should be able to guess until the correct number has been guessed. If an invalid number is entered, such as: 1.24 (real number), or asd (string). The program should tell user...

  • Write a Java application program that plays a number guessing game with the user. In the...

    Write a Java application program that plays a number guessing game with the user. In the starter code that you are given to help you begin the project, you will find the following lines of code: Random generator = args.length == 0 ? new Random() :                    new Random(Integer.parseInt(args[0])); int secret = generator.nextInt(100); You must keep these lines of code in your program. If you delete these lines, or if you change thse lines in any way, then your program...

  • A Backwards Guessing Game For this assignment, you will be a making a guessing game with...

    A Backwards Guessing Game For this assignment, you will be a making a guessing game with a twist. You will play the role of the computer, and the computer will try to guess the number. You will think of a number (you don’t have to read it in as input) between 1 and 100. You will create a loop that runs 5 times. In this loop, the computer will try to guess the number in the range it knows is...

  • 7.30 - Guess-the-Number Game (Project Name: GuessTheNumber) - Write an app that plays “Guess the Number”...

    7.30 - Guess-the-Number Game (Project Name: GuessTheNumber) - Write an app that plays “Guess the Number” as follows: Your app chooses the number to be guessed by selecting a random integer in the range 1 to 1000. The app displays the prompt "Guess a number between 1 and 1000: ". The player inputs a first guess. If the player’s guess is incorrect, your app should display Too high. Try again. or Too low. Try again. to help the player “zero...

  • Swift program: Develop an app that is a Number Guessing Game, (ex: one that allows a...

    Swift program: Develop an app that is a Number Guessing Game, (ex: one that allows a player to guess a number between a high and a low number, say between 1 and 10) with the system guiding the player by indicating whether the number is too high or too low after an incorrect guess. This process is repeated until the player correctly guesses the number or simply quit your app. For simplicity purposes, assume the magic number to be guessed...

  • Write a C++ program to play the number guessing game with user as follows.

    Write a C++ program to play the numberguessing game with user as follows.The user determines a number between 1~100.The program has 4 tries to guess the number byproviding a range (low, high) on each try.The user tells the program whether the number isbelow, within, or above the range.The program announces a game loss after 4 incorrecttries.

  • In Java You’re going to make a Guess the Number game. The computer will "think" of...

    In Java You’re going to make a Guess the Number game. The computer will "think" of a secret number from 1 to 20 and ask the user to guess it. After each guess, the computer will tell the user whether the number is too high or too low. The user wins if they can guess the number within six tries. The program should look like this in the console, player input is in bold: Hello! What is your name? Abaddon...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT