Matrix dimensions must agree - 3 chances loop
Afficher commentaires plus anciens
Hi, I need help with a code I'm trying to run.
I'm trying to run it so you have 3 chances to guess a string variable correctly, and after the third, it says incorrect, or if any of the guesses are correct then the code ends and just says you have guessed correctly.
The code is shown below that I am using: (The error shown is that Matrix dimensions must agree - the code runs perfectly with correct guesses or when I guess food which has 5 letters)
FavFood=('Pizza');
y=input('What is my favourite Food? ','s');
if y==FavFood
disp('Well done, you guessed correctly');
else x=input('Sorry, you guessed wrong. Try again: ','s');
if x==FavFood
disp('Well done, you guessed correctly');
else z=input('Sorry, you guessed wrong. Try again: ','s');
if z==FavFood
disp('Well done, you guessed correctly');
else disp('Sorry, you ran out of chances.');
end
end
end
Many thanks,
EDIT: typo
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!