LeapYear Loop/Repeat

3 次查看(过去 30 天)
Ainars Cernavskis
编辑: Sam 2021-7-6
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

回答(1 个)

Sam
Sam 2021-7-6
编辑:Sam 2021-7-6
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

类别

Help CenterFile Exchange 中查找有关 Graphics Performance 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by