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 program should ask them if they want to play again. (Note: The program should use at least one function.)
For example:
Enter a guess 1-50, or 0 to quit: 25
Too high!
Enter a guess 1-50, or 0 to quit : 15
Too low!
Enter a guess 1-50, or 0 to quit : 18
That's it!
You took 3 guesses to get the number.
Would you like to play again? (Y/N) N
Good bye!
Note: The program should include appropriate input validation and error checking.
Submit:
`Hey,
Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries
//header files
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
int number, i;
char ans;
srand(time(NULL));
//creating random number between 1 to 50
number = 1 + rand()%50;
//printing the random number to identify the guess
int guess;
int count=0;
do
{
cout<<"Enter a guess 1-50, or 0 to quit: ";
do
{
//enter a guess
cin>>guess;
if(guess==0)
return 0;
//if guess is equal to number
if(guess == number)
{
cout<<"That's it! You took "<<count<<" guesses to get the number."<<endl;
break;
}
//if guess is less than number
else if(guess < number && guess >0 && guess <=50)
{
count++;
cout<<"Too low!\nEnter a guess 1-50, or 0 to quit: ";
}
//if guess is greater than number
else if(guess > number && guess >0 && guess <= 50)
{
count++;
cout<<"Too high!\nEnter a guess 1-50, or 0 to quit: ";
}
//if guess in not in valid range
else if(guess<0 || guess > 50)
{
count++;
cout<<"Invalid!Try again: ";
}
}while(guess != number);
cout<<"Would you like to play again? (Y/N) ";
cin>>ans;
if(ans != 'y' && ans != 'Y')
{
break;
}
}while(ans == 'y' || ans == 'Y');
return 0;
}//end of the class
Pseudo code:
start
generate random number
Accept guess number from user
while(repeat=='Y') do
while(1) do
if(guess==0) do
quit the program
end if
Increment count
if(guess > number)
print Too high!
end if
else if (guess < number)
Too low!
end else if
else
That's it!
print number of guesses to get the number
end else
Accept guess number from user
end while
print Would like to play again? (Y/N)
accept choice
end while
Kindly revert for any queries
Thanks.
This program will implement a simple guessing game... Write a program that will generate a random...
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...
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...
on python i need to code a guessing game. After the player has guessed the random number correctly, prompt the user to enter their name. Record the names in a list along with how many tries it took them to reach the unknown number. Record the score for each name in another list. When the game is quit, show who won with the least amount of tries. this is what i have so far: #Guess The Number HW assignment import...
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 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...
For this lab you will write a Java program using a loop that will play a simple Guess The Number game. Th gener e program will randomly loop where it prompt the user for a ate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a r has guessed the correct number, the program will end with a message indicating how many guesses it took to get the right answer and 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...
Python Program Python: Number Guessing Game Write a Python function called "Guess.py" to create a number guessing game: 1. Function has one input for the number to Guess and one output of the number of attempts needed to guess the value (assume input number will always be between 1 and 1000). 2. If no number was given when the function was called, use random.randint(a,b) to generate a random number between a=1 and b=1000. You will also need to add an...
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...
Write a program to play "guess my number". The program should generate a random number between 0 and 100 and then prompt the user to guess the number. If the user guesses incorrectly the program gives the user a hint using the words 'higher' or 'lower' (as shown in the sample output). It prints a message 'Yes - it is' if the guessed number is same as the random number generated. ANSWER IN C LANGUAGE. ====================== Sample Input / Output:...