Matlab code problems I have to write a code using functions to find out if a...

80.2K

Verified Solution

Question

Programming

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

Answer & Explanation Solved by verified expert
4.5 Ratings (825 Votes)
So total there are few changes that you need to do so as to remove error 1 In project7mfp You need to modify line 22 such that year getDataRangeEnter the year 1582 inf And in getDataRange function modify line 1 as function year getDataRangeprompt a b This will pass value of year user will type from getDataRange function to project7mfp function 2 Modify line 30 to leap isLeapYearyear This will pass value of leap from isLeapYear function to project7mfp function 3 Finally there is logical error in function isLeapYear In line 20 of this    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students