LeapYear Loop/Repeat
2 views (last 30 days)
Show older comments
So i made a leap year calculator and each time when it displays an answaer that its a leap year or not it asks the user if they want to repeat or not , but i dont know how to make it so it would repeat/loop .If you could show me where/what i missed would be great .
function year
year = input (' Enter the year : ');
if mod(year,4) == 0 disp ('Is a leap year')
condition = input("Would you like to repeat? (yes/no)\n", 's') == "yes";
elseif mod(year,100) == 0 disp ('false')
elseif mod(year,400) == 0 disp ('true')
else disp ('Is not a leap year')
condition = input("Would you like to repeat? (yes/no)\n", 's') == "yes";
end
clc
0 Comments
Answers (1)
Sam
on 6 Jul 2021
Edited: Sam
on 6 Jul 2021
function year
condition = "yes"
while strcmp(condition,"yes") == 1
year = input (' Enter the year : ');
if mod(year,4) == 0
if mod(year,400) == 0 disp ('true')
elseif mod(year,100) == 0 disp ('false')
else disp ('true')
else disp ('false')
end
condition = input("Would you like to repeat? (yes/no)\n", 's') == "yes";
end
0 Comments
See Also
Categories
Find more on Logical 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!