Random number game repetition help
Show older comments
I am trying to create a number guessing game that keeps repeating until you guess the number. If I guess the number correct then I want it to ask to keep playing. If the user wants to keep playing, the code should repeat, but it is not working right now.
clear
clc
startChoice = input('Would you like to play this high-tech game? Enter 1 for yes and 0 for no!');
guessNumber = randi([1 50],1,1);
while startChoice == 1
guess = input('What number do you pick? ')
if guess < guessNumber
startChoice = input('You guessed to low. Would you like to keep trying? 1 for yes, 0 for no. ')
elseif guess > guessNumber
startChoice = input('You guessed to high. Would you like to keep trying? 1 for yes, 0 for no. ')
elseif guess == guessNumber
startChoice = input('You guessed correct! Would you like to play again? 1 for yes, 0 for no. ')
while startChoice == 1
guessNumber = randi([1 50], 1, 1);
guess = input('What number do you pick? ')
end
end
end
if startChoice == 0
disp('Wowwwww, you are no fun!')
end
Accepted Answer
More Answers (1)
Tyler Temme
on 17 Oct 2018
0 votes
Categories
Find more on Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!