LeapYear Loop/Repeat

4 visualizaciones (últimos 30 días)
Ainars Cernavskis
Ainars Cernavskis el 6 de Jul. de 2021
Editada: Sam el 6 de Jul. de 2021
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

Respuestas (1)

Sam
Sam el 6 de Jul. de 2021
Editada: Sam el 6 de Jul. de 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

Categorías

Más información sobre Graphics Performance en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by