Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using MATLAB write a code for the following: Write a MATLAB program that will pr

ID: 2079857 • Letter: U

Question

Using MATLAB write a code for the following:

Write a MATLAB program that will prompt the user to enter the current month as a string (like "September" or "September"), then display the number of days in the month that they specified. Note that September, April, June, and November have 30 days, February has 28 or 29 days, and all the other months have 31 days. If the user does not enter a valid month name, display an appropriate error message. The program should continue running until the user input the string "Exit" or "exit".

Explanation / Answer

Matlab Code:

month = input('Enter month:','s');
while (1==1)
if strcmp(month,'Exit') || strcmp(month,'exit')
break;
end
if strcmp(month,'Febraury')||strcmp(month,'febraury')
fprintf('The number of days in %s is %d ',month,28);
elseif strcmp(month,'September')||strcmp(month,'september') || strcmp(month,'April')||strcmp(month,'april')|| strcmp(month,'June')||strcmp(month,'june') || strcmp(month,'November')||strcmp(month,'november')
fprintf('The number of days in %s is %d ',month,30);
elseif strcmp(month,'January')||strcmp(month,'january') || strcmp(month,'March')||strcmp(month,'march')|| strcmp(month,'may')||strcmp(month,'May') || strcmp(month,'July')||strcmp(month,'july')||strcmp(month,'August')|| strcmp(month,'august')||strcmp(month,'October') || strcmp(month,'october')||strcmp(month,'December')||strcmp(month,'december')
fprintf('The number of days in %s is %d ',month,31);
else
disp('Please enter valid month');
end
month = input('Enter month: ','s');
end

command window output:

Enter month:hello
Please enter valid month
Enter month:
January
The number of days in January is 31
Enter month:
exit
>>