Question

The price for renting a car at a car rental company is according to the following schedule: Sedan SUV Duration of rent Daily Free Cost of Daily Free Cost of rate miles Additional rate miles Additional (per day) mile (per day) mile 1-6 days $79 80 $0.69 $84 80 $0.74 7-29 days $69 100 $0.59 $74 100 $0.64. 30 or more days $59 120 S049 $64 120 $0.54 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: (a) Sedan, 10 days, 769 miles. (b) SUV, 32 days, 4,056 miles. (c) Sedan, 3 days, 511 miles. Hint: Use a switch-case structure for the type of the car (Sedan SUV) with nested alternative if structure for the number of days and miles. Use printf 0 to display the text and data. The data should be displayed in f format with two decimal digits.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
car_type = input('Enter car type: ', 's');
num_days = input('Enter number of days: ');
num_miles = input('Enter miles driven: ');
total_cost = 0;

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

fprintf('The rent costs $%0.2f\n', cost);
Add a comment
Know the answer?
Add Answer to:
The price for renting a car at a car rental company is according to the following...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • i need the answe clear in mat lab, i need the in put and out put...

    i need the answe clear in mat lab, i need the in put and out put please 6 29. Write a program in a script file that calculates the cost of renting a according to the following price schedule: 217 Sedan Duration of rent Daily SUV Free Cost of miles additional (per day) mile Daily Free miles Cost of additional (per day) mile rate rate 1-6 days $79 80 $0.69 $84 80 $0.74 7-29 days $69 100 $0.59 $74 100...

  • in python create a program to display the cost of renting a smart car. the user...

    in python create a program to display the cost of renting a smart car. the user must be able to enter the number of days he/she rents the cat and the number of miles driven. use constants for the flat rate per day and the flat rate per mile. the program will display the flat rate per day, flat rate per mile, and the total cost of the car rental.

  • *** USING C++ *** Create a file containing the following: car numbers, miles driven, and gallons...

    *** USING C++ *** Create a file containing the following: car numbers, miles driven, and gallons of gas used in each car (do not include the readings): Car Number 25 Gallons Used 65 138 36 Miles Driven 1500 3540 1889 2466 2265 68 87 Write a program that reads the data in the file and displays the car number, miles driven, gallons used and the miles per gallon for each car. The output should also contain the total miles drive,...

  • 1. Write a python script that will compute and display information for a company which rents...

    1. Write a python script that will compute and display information for a company which rents vehicles to its customers. For a specified customer, the program will compute and display the amount of money charged for that customer’s vehicle rental after prompting the user to enter the following four items for a given customer (in the specified order)  The car type (a character either C (compact), M (mid-size), L (luxury), S (SUV), or V (Van) )  The number...

  • Please help, need to code for this business assignment using c++. Business Expense Reimbursements Calculator Probl...

    Please help, need to code for this business assignment using c++. Business Expense Reimbursements Calculator Problem statement: Business trip is part of the enterprise culture. Suppose a businessperson just completed a business trip for your company. Now, you are tasked to write a program that calculates and displays the total travel expenses, allowable expenses for the trip, and the excess that must be paid by the businessperson, if any The program should prompt the user for the following . The...

  • On January 1st 2010, SRC company paid cash to purchase an automobile. The car dealer gave...

    On January 1st 2010, SRC company paid cash to purchase an automobile. The car dealer gave SRC $1,000 cash discount off of a $19,000 list price. However SRC paid an additional $2,000 to equip the automobile with more luxurious interior so would have a greater appeal to a client's. SRC expect the automobile to have a 4-year useful life and to lease it for 100,000 miles before disposing of it. SRC also estimates a salvage value of $4,000. SRC Lisa...

  • Use program control statements in the following exercises: Question 1 . Write pseudocode for the following:...

    Use program control statements in the following exercises: Question 1 . Write pseudocode for the following: • Input a time in seconds. • Convert this time to hours, minutes, and seconds and print the result as shown in the following example: 2 300 seconds converts to 0 hours, 38 minutes, 20 seconds. Question 2. The voting for a company chairperson is recorded by entering the numbers 1 to 5 at the keyboard, depending on which of the five candidates secured...

  • 1. Expense Pie Chart Create a text file that contains your expenses for last month in...

    1. Expense Pie Chart Create a text file that contains your expenses for last month in the following categories: -Rent -Gas -Food -Clothing -Car Payment -Misc Write a Python program that reads the data from the file and uses matplotlib to plot a pie chart showing you how you spend your money. 2. 1994 weekly gas graph The text file named 1994_Weekly_Gas_Averages.txt contains the average gas price for each week in the year 1994. (There are 52 lines in the...

  • CASE 1-5 Financial Statement Ratio Computation Refer to Campbell Soup Company's financial Campbell Soup statements in...

    CASE 1-5 Financial Statement Ratio Computation Refer to Campbell Soup Company's financial Campbell Soup statements in Appendix A. Required: Compute the following ratios for Year 11. Liquidity ratios: Asset utilization ratios:* a. Current ratio n. Cash turnover b. Acid-test ratio 0. Accounts receivable turnover c. Days to sell inventory p. Inventory turnover d. Collection period 4. Working capital turnover Capital structure and solvency ratios: 1. Fixed assets turnover e. Total debt to total equity s. Total assets turnover f. Long-term...

  • What happened on United flight 3411?What service expectations do customers have of airlines such ...

    What happened on United flight 3411?What service expectations do customers have of airlines such as United and How did these expectations develop over time? Thank You! In early April 2017, United Airlines (United), one of the largest airlines in the world, found itself yet again in the middle of a service disaster this time for forcibly dragging a passenger off an overbooked flight. The incident was to become a wake-up call for United, forcing it to ask itself what to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT