Applying LeapYear function into the Matlab Scipt
显示 更早的评论
Creat a function called isLeapYear(intYear) that determines if the input year is a leap year or not. Write the main program to calculate the total days passed in a year for a given date. Prompt the user for the (integer) inputs: year, month, and day. The output is the total days passed since Jan 1st of that year excluding the input date (e.g., if the user gives 2012, 01, 23, then the output is 22). Call the function isLeapYear(intYear) to determine if the year is leap or not, if necessary.
Here's my function:
function LeapYear = isLeapYear(intYear)
a = mod(intYear,400);
b = mod(intYear,100);
c = mod(intYear,4);
LeapYear = ((a==0)||(b~=0 && c==0));
end
Here's my main code:
clear,clc
%1. Get Inputs
intYear = input('Enter Year: ');
intMonth = input('Enter Month: ');
intDay = input('Enter Day: ');
%2. Calculate days passed
if isLeapYear==0
intDaysPassed = ((((intMonth - 1)*30)+intDay) - 1);
else
strMessage = 'Please enter a valid leap year';
msgbox(strMessage)
return
end
I tried using "isLeapYear==0" but it's not working. How would I be able to define if a function is true or not in order to proceed with the process?
Thank you so much !!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Satellite Mission Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!