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

Create an M-file exampb2.m that prompts user to enter scalar value of grocery bi

ID: 3837534 • Letter: C

Question

Create an M-file exampb2.m that prompts user to enter scalar value of grocery bill (dollars) in command window. Use input command to enter the value of bill. If the bill is equal or above 100, display 'your discount is 10 %'. If the bill is between 50 and 100, display 'your discount is 5 % '. If the bill is less than or equal to 50, display 'your discount is 2%'. Use structure. In the same main file, prompt the user to input his or her choice of destination from Amarillo by flight like Dallas, Houston, Albuquerque and Denver. The input will be a string. (use 's' in input command). Use switch/case structure to display price of one way ticket for each destination like $150 for Dallas, $200 for Houston, $125 for Albuquerque and $ 175 for Denver.

Explanation / Answer

HI,

Please find MATLAB code below. Save it in a m file and run. Thanks.


x = input('Please enter value of grocery bill(in dollars): ');
if x >= 100
disp(['Your discount is 10%']);
elseif (x >= 50) && (x < 100)
disp(['Your discount is 5%']);
else
disp(['Your discount is 2%']);
end
  
str = input('Please enter your destination from Amarillo by flight: ','s');
switch(str)
case 'Dallas'
disp('One way flight ticket for Dallas is $150' );
case 'dallas'
disp('One way flight ticket for Dallas is $150' );
case 'Houston'
disp('One way flight ticket for Houston is $200' );
case 'houston'
disp('One way flight ticket for Houston is $200' );
case 'Albuquerque'
disp('One way flight ticket for Albuquerque is $125' );
case 'albuquerque'
disp('One way flight ticket for Albuquerque is $125' );
case 'Denver'
disp('One way flight ticket for Denver is $175' );
case 'denver'
disp('One way flight ticket for Aenver is $175' );
otherwise
disp('Invalid destination entered.' );
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote