Write a C++ program main.cpp that implements a simple number guessing game with multiple questions / answers. For each game, the program generates a random number between 1 and 10. User enters an answer with a numeric input. If the user input number matches the generated number, then print a message to inform users that he/she has a correct guess. If the guess is not correct, allow the user to have two more chances to guess the correct number.
At any time, if users enter 0, then the program should display the game session summary and exits.
The program should keep track of the wins and losses and print the summary counts when user chooses to exit by entering 0.
The program should generate a new random number only after user enters the correct guess or after user has tried 3 times and did not have the right guess. Do not ask user for a yes/no confirmation after each game because the 0 input value will serve as the sentinel (Chapter 5 topic) to stop the continuous game.
Here is a sample run using command line.
At the program start, it shows:
“Welcome to the number guessing game.
For each game, you have at most 3 chances to guess a secret number from 1 to 10.”
The first time, when a new question is asked, the program displays:
“Enter a number from 1 to 10. Enter 0 to exit:”
When users give a wrong guess, it shows:
Not correct, try again:
When users give a wrong answer after the third trials for the same question, the program displays:
“Not correct. You have reached your third trials. The correct number is X.”
“Lets start a new secret number”
When users answer with the correct number, it shows this prompt:
“Congratulation, correct! Let’s start a new secret number.”
When users hit 0, the game summary is displayed:
Game summary:
Total games: 5
Total game wins: 3
Total game losses: 2
Notes:
Use the function rand() to generate random numbers.
Also use “time” and use the srand() to generate a random seed for the random generator. The srand() should be called only once outside the loop before the game starts.
In main(), you can use a “while“ loop that gets inputs.
To control the number of maximum trial answer per question, you should use a nested loop inside the main “while” loop. Using a nested "for" loop is fine.
Generate a new random number only when a new game starts after users either have entered the correct answer or users have exceeded the 3 trials.
For the count of losses, update the count only when users have exceeded the maximum 3 trials. Do not count as a loss if users have not finished the 3 trials.
You can use logical operators (AND, OR, NOT) to simplify code.
8. Add Comment at the top of your program:
/***************************************
/* Author:
/* Description:
/*
/***************************************
#source code:
#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;
int main(){
int secretNumber;
int guessNumber;
int win=0;
int loose=0;
int playGamesCount=-1;
int gameTrack=0;
cout<<"Welcome to the number guessing game.\n";
cout<<"For each game, you have at most 3 chances to guess a
secret number from 1 to 10.";
while(true){
srand(time(0));
secretNumber=rand()%10+1;
cout<<"\nEnter a number from 1 to 10. Enter 0 to
exit:";
gameTrack=0;
playGamesCount+=1;
while(gameTrack!=3){
cin>>guessNumber;
if(guessNumber==secretNumber){
cout<<"\nCongratulation, correct! Let’s start a new secret
number.";
win+=1;
break;
}
else if(guessNumber==0){
break;
}
else if(guessNumber!=secretNumber){
gameTrack+=1;
cout<<"Not correct, try again:";
}
}
if(guessNumber==0){
cout<<"Game Summary:\n";
cout<<"Total games:"<<playGamesCount<<"\n";
cout<<"Total game wins:"<<win<<"\n";
cout<<"Total game losses: "<<loose<<"\n";
break;
}
else if(gameTrack==3){
cout<<"\nNot correct. You have reached your third trials. The
correct number is "<<secretNumber;
loose+=1;
}
}
return 0;
}
#output:

Write a C++ program main.cpp that implements a simple number guessing game with multiple questions /...
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...
Write a program that allows a user to play a guessing game. Pick a random number in between 1 and 100, and then prompt the user for a guess. For their first guess, if it’s not correct, respond to the user that their guess was “hot.” For all subsequent guesses, respond that the user was “hot”if their new guess is strictly closer to the secret number than their old guess and respond with“cold”, otherwise. Continue getting guesses from the user...
Number Guessing Game Games Write program in C++. For this game, the computer will select a random number between 1 and 100 (inclusive). The computer will then ask the (human) player to guess the number the computer has selected. After the player’s guess is input to the computer, the computer will output one of three responses, depending on the relationship of the number the player guessed to the number the computer selected: “Your guess was too low.” “Your guess was...
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...
please c++ with functions *Modify the Guessing Game Write the secret number to a file. Then write each user guess and answer to the file. (on separate lines) Write the number of guesses to the file at the end of the game. After the game is finished, ask the user if they want to play again. If 'n' or 'N' don't play again, otherwise play again! NOTE: your file should have more than one game in it if the user...
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...
Task 4 (20 points) Implement a simple guessing game. Name your file task4.c. Your game will use rand() to generate a random number from 1 to 10 then prompt user to guess that number. User will have unlimited number of tries to guess the correct number. Your program should work like this hb117@uxb4:$ gco -Wall task4 . c -o task4 hb117@uxb4:~$ ./guessing Guess a number from 1-10: 1 Guess again: 4 Guess again: 2 Guess again: 9 Guess again: 10...
newd in C++
Exercise #3 Guess the Number Write a "Guess the Number" game that randomly assigns a secret number [1,20] for the user to guess. I recommend hard coding your secret number at first to make testing your code easier. You can write this a number of ways, but try to stick to the instructions outlined here. Write three methods to make your game work. The first method should generate a random number and return the value to main...
Java Guessing Game Class The class will generate a random number of 1 to 15, and then check to see if the user guessed the number correctly. If the number is incorrect, the user should have the chance to guess again, until they guess the right number or they guess 10 times. The class method should keep track of the number of guesses the user has had, and return this value. The class should have one constructors, a default and...
c++ launguage please help The game Pico Fermi Bagel is a number guessing game. The computer picks a secret number: the secret number must be 3 digits, none of the digits can be the same, and it cannot start with a zero. 104 is OK, but 091 and 212 are not. The user tries to guess the secret number - if none of the digits in the user's number are in the secret number, then the program replies with BAGEL...