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

A car rental company uses the following table to help compute rental fees. Car T

ID: 3651100 • Letter: A

Question

A car rental company uses the following table to help compute rental fees.
Car Type Rate per Day Rate per Mile
Chevrolet 50.00 0.27
Corvette 85.00 0.45
Pontiac 53.00 0.32
Buick 60.00 0.32
Oldsmobile 60.00 0.35
Cadillac 70.00 0.40

Write a program to calculate car rental fees based on this table. The program should prompt the user to enter the name of the type of car that was rented, the number of days the car rented, and the number of miles the car was driven. The program should search the table for a match on the car type. If there is a match, the rental fee is the number of days rented, times the rate per day, plus the number of miles traveled, times the rate per mile. The program should display the type of car, the number of days rented, the number of miles driven, and the rental fee. If the table search cannot find the car type in the table, display an appropriate error message. Write the program to process any number of rentals.

Explanation / Answer

Slight Modification:

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    while(1)
    {
        cout<<" Enter car type: ";
        char car[20];
        cin>>car;
        cout<<"Enter the number of days the car was driven: ";
        double d;
        cin>>d;
        cout<<"Enter the number of miles the car was driven: ";
        double m;
        cin>>m;
        double rt,rm;
        if(strcmp(car,"Chevrolet")==0){rt=50;rm=0.27;}
        else if(strcmp(car,"Corvette")==0){rt=85;rm=0.45;}
        else if(strcmp(car,"Pontiac")==0){rt=53;rm=0.32;}
        else if(strcmp(car,"Buick")==0){rt=60;rm=0.32;}
        else if(strcmp(car,"Oldsmobile")==0){rt=60;rm=0.35;}
        else if(strcmp(car,"Cadillac")==0){rt=70;rm=0.40;}
        else {cout<<"Car not found, enter again";continue;}

        double rental=(d*rt)+(m*rm);
        cout<<" The car "<<car<<" drove "<<d<<" days and ";
        cout<<m<<" miles and rental fee is $"<<rental;

        cout<<" Do you want to enter more cars[y for yes]: ";
        char ch;
        cin>>ch;
        if(ch!='y')break;
    }
}

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