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

create a matlab file i have this for 3a, but it is not working 3. Use the switch

ID: 3864571 • Letter: C

Question

create a matlab file

i have this for 3a, but it is not working

3. Use the switch/case statement to solve the following problems. a) Create a program to prompt user to enter year in school (freshman, sophomore, junior, senior). Input should be a string. Determine the day finals will be given for each group: Monday for freshmen, Tuesday for sophomores, Wednesday for juniors, and Thursday for seniors. b) Create a program to prompt users to enter the number of candy bars they would like to buy. Input should be a number. Determine the bill (a bar- $1.50, 2 bars $2.50, 3 bars 3.30, more than 3 bars -$3.30+$0.60x(# ordered- 3)

Explanation / Answer

main3a.m

clc;
close all;
clear all;
year=input('Please enter year in school:','s')
error=0;
switch year
    case 'freshman'
        disp('Monday');
    case 'sophomore'
        disp('Tuesday');
    case'junior'
        disp('Wednesday');
    case 'senior'
        disp('Thursday');
    otherwise
        error=1;
        disp('error in input');
end

Output:-

Please enter year in school:freshman

year = freshman

Monday

main3b.m

clc;
close all;
clear all;
number=input('Please enter the number of candy bars you would like to buy:')
switch number
    case 0
        disp('the bill is zero');
    case 1
        disp('the bill is $1.50');
    case 2
        disp('the bill is $2.50');
    case 3
        disp('the bill is $3.30');
    otherwise
        bill=(3.30+(0.60*(number-3)));
        disp('the bill is $');
        disp(bill);
end

Output:-

Please enter the number of candy bars you would like to buy:4

number =

     4

the bill is $
    3.9000