% get the month and year
disp('Program to calculate number of days');month = input('Enter the month (1-12): ');year = input('Enter the year (####): ');% To check the leap year
if mod(year,400) ==0 leap_year =1;elseif mod(year,100) ==0 leap_year =0;elseif mod(year,4) ==0 leap_year =1;else leap_year =0;end% calculate days in months
switch (1) case 1;3;5;7;8;10;12; days = 31; case 4;6;9;11; days =30; case 2 days=28 + leap_year;end%print the days
fprintf ('The number of days in the month %2d is %2d days. \n',month , days) ;
MATLAB: Program not running correctly. Trying to write program to determine number of days in month.
errorMATLABmonthprogramming
Related Question
- How to request additional data from the user in a function
- How to solve this error
- Function that transforms years into days
- Is there a more simple way to express this? How to simplify everything under “case 2”? Is there an alternative to writing out everything under case 2
- Still using a switch structure, now within a function. I keep getting an error message saying I don’t have enough input arguments for (line 6).
- Convert hour, minute, and day to fraction of a day
Best Answer