create a script guessing_game.m
computer generates a random integer between 1 and 20 inclusive
allow the user to guess 5 times or until the user gets the correct answer
count and display the number of guesses before a correct answer was made
stop if the user does not put in a value
display an appropriate message if the user wins or gives up
display a hint if the user gets the wrong value
script name guessing_game
intput variable: computer
input variable: guess
output variable: result
result = 0 if the user did not enter a value the loop exits (guess is an empty vector)
result = 1 if the user wins (matches the computer value)
result = 2 if the user loses (does not match after 5 guesses)
output variable: hint
hint = ‘low’ if the guess is low
hint = ‘high’ if the guess is high
output variable: count = number of guesses that the user makes including the winning guess
Comments
Leave a comment