In: Computer Science
Question #11. Write a script that uses the menu function to prompt the user to select the current day of the week. Then use the menu function to prompt the user to select their favorite day of the week. Print a message telling the user how many days it will be until their favorite day. The output must include the current day, the favorite day, and the number of days until the favorite day. Debug your programming by running it many times and testing it with different input combinations. Here are some sample runs
matlab
Hi,
Please find the matlab script below:
-------------------------------------
Sample Matlab Script:
% Prompt the user for current day of the week
Weekdays={'Mon','Tue','Wed','Thu','Fri','Sat','Sun'};
CurrentDay = menu('Select Current
Day','Mon','Tue','Wed','Thu','Fri','Sat','Sun');
% Prompt the user for favorite day of the week
FavoriteDay = menu('Select Favirite
Day','Mon','Tue','Wed','Thu','Fri','Sat','Sun');
fprintf('The Current Day is = %s\n',weekdays{CurrentDay});
fprintf('My Favorite Day is = %s\n',weekdays{FavoriteDay});
% Straight forward case
if CurrentDay < FavoriteDay
fprintf('Number of days until the favorite day
is = %d days \n',FavoriteDay -CurrentDay);
else
%Round trip of the week
DayRemaining= 7-CurrentDay;
fprintf('Number of days until the favorite day =
%d days \n',DayRemaining + FavoriteDay);
end
Screenshot:
Run the program and verify the output.
Script Output:
>> NumberOfWeekDays
The Current Day is = Mon
My Favorite Day is = Sun
Number of days until the favorite day is = 6 days
>> NumberOfWeekDays
The Current Day is = Sat
My Favorite Day is = Tue
Number of days until the favorite day = 3 days
-----------------------------------------------------------
Hope this helps.