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

The price for renting a car at a car rental company is according to the followin

ID: 3834070 • Letter: T

Question

The price for renting a car at a car rental company is according to the following schedule: Write a MATLAB program in a script file that calculates the cost of renting a car based on the shown price schedule. The program must ask the user to enter the type of car (Sedan or SUV), the number of days, and the number of miles driven. The program then displays the cost (rounded to cents) for the rent in a sentence that reads: "The cost of the rent is XXX $." where XXX is the cost value in $. Run the program three times for the following cases: Sedan, 10 days, 769 miles. SUV, 32 days, 4, 056 miles. Sedan, 3 days, 511 miles. Use fprintf () to display the text and data. The data should be displayed in f format with two decimal digits.

Explanation / Answer

%matlab code

carType = input('Enter car type: ','s');
days = input('Enter number of days: ');
miles = input('Enter miles driven: ');
cost = 0;

switch(carType)
case 'Sedan'
if days <= 6
cost = 79;
if miles > (days*80)
cost = cost + (days-80)*0.69;
end
elseif days <= 29
cost = 69;
if miles > (days*100)
cost = cost + (days-100)*0.59;
end
else
cost = 59;
if miles > (days*120)
cost = cost + (days-120)*0.49;
end
end
  
case 'SUV'
if days <= 6
cost = 84;
if miles > (days*80)
cost = cost + (days-80)*0.74;
end
elseif days <= 29
cost = 74;
if miles > (days*100)
cost = cost + (days-100)*0.64;
end
else
cost = 64;
if miles > (days*120)
cost = cost + (days-120)*0.54;
end
end
  
otherwise
fprintf('Invalid Input ' );
quit
end

fprintf('The cost of the rent is %0.2f $ ', cost);


%{
output:

Enter car type: SUV
Enter number of days: 230
Enter miles driven: 432
The cost of the rent is 64.00 $

%}

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