Question

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.

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

MatLab program

clear all
clc
% generating random number
% 0 and 10 are the limits of random number
R=randi([0,10],1);
% asking user to guess
Ru=input('guess the random number: ');
while R~=Ru
    if Ru>R
        fprintf('Too high, try again\n');
    elseif Ru<R
        fprintf('Too low, try again\n');
    end
    Ru=input('Again guess the number: ');
end
fprintf('\n You correctly guessed number');

Screenshot

Save the above program and execute it.

Result

I hope this will help you

Add a comment
Know the answer?
Add Answer to:
Solve Question using While loops-MATLAB Write a program that generates a random number and asks the...
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
  • (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...

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

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

  • Hello! we are using Python to write this program. we are supposed to use loops in...

    Hello! we are using Python to write this program. we are supposed to use loops in this assignment. I would greatly appreciate the help! Thank you! Write a program that allows the user to play a guessing game. The game will choose a "secret number", a positive integer less than 10000. The user has 10 tries to guess the number. Requirements: we would have the program select a random number as the "secret number". However, for the purpose of testing...

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

  • Use visual studio C# Tasks You are going to build a program that generates a random...

    Use visual studio C# Tasks You are going to build a program that generates a random integer between 1 and 10, then prompts user to make several guesses of the number until user gets the right number - For each guess, tell user if the guess is higher or lower than the number - Handle the potential exception with user guess. Sample Output DAC programPrajects ExameExam1bin,DebugExarm1.exe Welcome! Guess the number I'm thinking of . It is between 1 and 1e...

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

  • Can someone upload a picture of the code in matlab Write a "Guess My Number Game"...

    Can someone upload a picture of the code in matlab Write a "Guess My Number Game" program. The program generates a random integer in a specified range, and the user (the player) has to guess the number. The program allows the use to play as many times as he/she would like; at the conclusion of each game, the program asks whether the player wants to play again The basic algorithm is: 1. The program starts by printing instructions on the...

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

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