The price for renting a car at a car rental company is according to the followin
ID: 3840659 • 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
Use the following matlab script to get the desired result:
prompt = "Enter the type of car [Sedan/SUV]: ";
type = input( prompt , 's' );
prompt = "Enter no. of days: ";
days = input( prompt );
prompt = "Enter miles to be driven: " ;
miles = input( prompt );
switch(type)
case "Sedan"
if( days < 7 )
cost = 79 ;
if( ( miles-80 ) > 0)
cost += (miles-80) * 0.69;
else if( days < 30 )
cost = 69 ;
if( ( miles-100 ) > 0)
cost += (miles-100) * 0.59;
else
cost = 59 ;
if( ( miles-120 ) > 0)
cost += (miles-120) * 0.49;
case "SUV"
if( days < 7 )
cost = 84 ;
if( ( miles-80 ) > 0)
cost += (miles-80) * 0.74;
else if( days < 30 )
cost = 74 ;
if( ( miles-100 ) > 0)
cost += (miles-100) * 0.64;
else
cost = 64 ;
if( ( miles-120 ) > 0)
cost += (miles-120) * 0.54;
fprintf( " The cost of rent is %0.2f $ ", cost);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.