LeapYear Loop/Repeat

조회 수: 10 (최근 30일)
Ainars Cernavskis
Ainars Cernavskis 2021년 7월 6일
편집: 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