LeapYear Loop/Repeat

2 Ansichten (letzte 30 Tage)
Ainars Cernavskis
Ainars Cernavskis am 6 Jul. 2021
Bearbeitet: Sam am 6 Jul. 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

Antworten (1)

Sam
Sam am 6 Jul. 2021
Bearbeitet: Sam am 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

Kategorien

Mehr zu Graphics Performance finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by