Write a program using a while loop that will have the user b

Write a program using a while loop that will have the user begin with a number and then have them keep guessing till they get the correct answer. Tell the user that they either need to go up or down. For example, if the correct number is 20 and the user picks 10, you will prompt to the command window, please enter a higher value. Continue with the prompts till the user selects the correct answer.

Solution

num = 54;
descript1 = \'Guess the number: \';%will be used while taking the input from user
while 1==1
n = input(descript1);
if n<num%if user input is less than corrent number then we ask them to go up
descript1 = \'you need to go up: \';
elseif n>numif user input is greater than corrent number then we ask them to go down
descript1 = \'you need to go down: \';
else
break;
end
end
disp(\'you guess it right: \');
disp(num);

Command window output:

Guess the number: 67
you need to go down: 46
you need to go up: 54
you guess it right:
54

 Write a program using a while loop that will have the user begin with a number and then have them keep guessing till they get the correct answer. Tell the user

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site