Solve using MATLAB Someone has created the following code to

Solve using MATLAB

Someone has created the following code to display the frequency of subway trains in a terminal and the names of the train lines are A, B, C, D and E. Rewrite the code using a switch structure (rather than the nested if), but do not change the prompt. You may assume the user enters an upper case letter at the prompt. Line = input(\'Enter the line.\', \' s\') if Line > \'A\' & Line

Solution

train =input(\"Enter name of the train\")

switch(train)
   case \'A\'
       fprintf(\'This train arrives every 24 minutes.\ \' );
   case \'C\'
       fprintf(\'This train arrives every 12 minutes.\ \' );
   case \'B\'
   case \'D\'
       fprintf(\'This train arrives every 18 minutes.\ \' );
  
   case \'E\'
       fprintf(\'This train arrives every 30 minutes.\ \' );
  
  
    otherwise
       fprintf(\'This train is not in service\ \' );
end

Solve using MATLAB Someone has created the following code to display the frequency of subway trains in a terminal and the names of the train lines are A, B, C,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site