Question

In c# create a program that generates a random number from 1 to 1000. Then, ask...

In c# create a program that generates a random number from 1 to 1000. Then, ask the user to guess the random number. If the user's guess is too high, then the program should print "Too High, Try again". If the user's guess is too low, then the program should print "Too low, Try again". Use a loop to allow the user to keep entering guesses until they guess the random number correctly. Once they figure it, congratulate the user. Hint: Make sure to generate the random number only once; otherwise, they will probably never finish. Pseudocode: seed random set random to value between 1 and 1000 get guess from user while guess does not equal random if guess is less than random print "Too Low" message else if guess is greater than random print "Too High" Message get guess from user end loop print "congratulation" message

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

using System;

class GuessGame {

static void Main(string[] args)

{

Random random = new Random();

//generating random number

int randomNumber = random.Next(1,100);

int userChoice = 0;

while (userChoice != randomNumber)

{

//reading user guess

Console.Write("Guess number: ");

userChoice=Convert.ToInt32(Console.ReadLine());

//checking if it high

if (userChoice > randomNumber)

{

Console.WriteLine("too high!");

}

//checking if it low

else if (userChoice < randomNumber)

{

Console.WriteLine("too low!");

}

else

{

Console.WriteLine("Correct! Congratulations.");

}

}

}

}

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
In c# create a program that generates a random number from 1 to 1000. Then, ask...
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
  • Solve Question using While loops-MATLAB Write a program that generates a random number and asks the...

    Solve Question using While loops-MATLAB Write a program that generates a random number and asks the user to guess what the number is. If the user's guess is higher than the random number, the program should display "Too high, try again." If the user's guess is lower than the random number, the program should display "Too low, try again." The program should use a loop that repeats until the user correctly guesses the random number.

  • (c++) Write a program that generates a random number between 1 and 100 and asks the...

    (c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...

  • Write a C program that generates a random number between 0 and 50. Then, the program...

    Write a C program that generates a random number between 0 and 50. Then, the program prompts for guesses until the user is correct, or has made 10 wrong guesses. After each guess, the program indicates whether the guess was too high, too low, or correct. Once the round has ended, either by a correct guess or by using up the 10 guesses, the program displays the current status.

  • 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...

  • Write a program that prompts the user for an integer that the player (maybe the user,...

    Write a program that prompts the user for an integer that the player (maybe the user, maybe someone else) will try to guess. If the player's guess is higher than the target number, the program should display "too high" If the user's guess is lower than the target number, the program should display "too low" The program should use a loop that repeats until the user correctly guesses the number. Then the program should print how many guesses it took....

  • Write a C++ program that generates a random number from 0 to 9. It will then...

    Write a C++ program that generates a random number from 0 to 9. It will then prompt the user to guess the random number it generated. Your program stops if the user guesses the right number. (Use the cout function to display the random number the computer generates so that you can determine if your code actually works). SAMPLE OUTPUT Random number = 8 Guess a number in the range [0,9]: 1 Too low Guess a number in the range...

  • Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask...

    Create a JavaFX game: Guess the Number create a random # between 1 and 1000 Ask user for a guess; possible answers TOO LOW TOO HIGH WINNER! print guess to screen if the user wins, write the random number, and all the guesses to a file. If the user doesn't guess in 10 turns, display the number. NOTES: You may want to implement: Restart option Best Guess statistic (game 1 took 8 tries, game 2 took 5 - 5 is...

  • Create a HTML with Java Script such that you input a number between 222 and 333....

    Create a HTML with Java Script such that you input a number between 222 and 333. Then the user needs to guess the number. If the user’s guess is higher than the number, the program should display “Too high, try again.” If the user’s guess is lower than the number, the program should display “Too low, try again.” If the difference is less than 10, it should also mention "too close". When the user guesses the number, the program should...

  • Guess the number! You will create a program that will ask the user to guess a...

    Guess the number! You will create a program that will ask the user to guess a number between 1 and 10. The pseudocode is below. Be sure to import random at the beginning of your code and use a comment block explaining what your program does #Guess the number week 4 #Name: #Date: #Random number, loop while true #ask user for number. #if number is too high or too low, tell user, if they guessed it break out of loop...

  • umber of inches of rain for month 66 umber of inches of rain for month 75...

    umber of inches of rain for month 66 umber of inches of rain for month 75 umber of inches of rain for month s 4 umber of inches of rain for month 9 umber of inches of rain for month 1e umber of inches of rain for month 11 45 umber of inches of rain for month 12? ver a period of 24 months, 168 inches of rain fell 11. Random Number Guessing Game (6 points) Write a program that...

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