Matlab code problems
I have to write a code using functions to find out if a year isa leap year. I'm on the write track i feel like but I keep gettingan error message and matlab isnt helping to troubleshoot. The issueis on line 30. Here is my code:
function project_7_mfp()
%Â Â PROJECT_7_ABCÂ Â project_7_abc() creates afunction that prompts the user
%Â Â enter a year after 1582 It then determines if it is aleap year
%
%Â Â Name:
%Â Â Date:
%Â Â Class: CMPSC 200
%
  %  Print the splash screen using aprintHeader() function
 Â
    Â
  % Prompt the user for the single data input for theprogram. This
  %  is the year. You will need to write alocal function called getDataRange().
  %  Then call it here. The function willreturn a single input. The
  %  getDataRange function must error checkthe input to be sure that is at
  %  least 1582 when the Gregorian calendaywas enacted.
 Â
  global debug
debug = 0;
 Â
  getDataRange('Enter the year: ', 1582, inf);
if(debug)
  fprintf('You entered %f\n', year);
end
 Â
%Â Â Call isLeapYear(year) to check if the year is a leapyear.
 Â
  isLeapYear(year);
  %  Use printResults to print if the year isa leap year or not
printResults(year, leap)
end
function getDataRange(prompt, a, b)
%Â Â GETDATARANGEÂ Â getDataRange(prompt, a, b)is a wrapper function to enter
%Â Â and error check that input. prompt is a variablestoring the prompt to be
%Â Â printed. a and b are the minimum and maximum valuesfor the error checking
%
%Â Â Name:Â Â Â Â Â
%Â Â Class:Â Â Â Â Â CMPSC 200
%Â Â Date:Â Â Â Â Â
%
 Â
global debug
  year = input(prompt);
 Â
assignin('base','year',year)
if(debug)
fprintf('Calling the selection to check if the value is withinrange\n');
end
%error check
 Â
if ((year < a) || (year > b))
 Â
if(debug)
fprintf('The value is out of range so throw an exception andexit\n');
end
 Â
error('Entered value, %f, is outside of the range of %f to %f',year, a, b);
end
 Â
if (mod(year,1) ~=0)
  error('Entered value, %f, is not an integer',year);
end
 Â
end
function leap = isLeapYear(year)
%Â Â ISLEAPYEARÂ Â isLeapYear(year) checks theinput to determine if it is a leap
%Â Â year. If it is, the function returns 1. If it is notit returns 0
%
%Â Â Name:Â Â Â Â Â
%Â Â Class:Â Â Â Â Â CMPSC 200
%Â Â Date:Â Â Â Â Â
%
 Â
%failure
assignin('base','year',year)
  if (mod(year,400)==0)
leap = 1;
elseif (mod(year,100)==0)
leap = 0;
elseif (mod(year,4)==0)
leap = 1;
else
leap = 1;
 Â
end
 Â
 Â
 Â
 Â
end
function printResults(year, leap)
%Â Â PRINTRESULTSÂ Â printResults(year, leap)prints a statement indicating
%Â Â if the year is a leap year or if it is not.
%
%Â Â Name:Â Â Â Â Â
%Â Â Class:Â Â Â Â Â CMPSC 200
%Â Â Date:Â Â Â Â Â
%
  if leap == 1
fprintf('%f is a leap year', year);
elseif leap == 0
fprintf('%f is not a leap year', year);
end
 Â
 Â
 Â
 Â
 Â
 Â
end