Answer to Question #245237 in C++ for Jnr

Question #245237

This test requires you to implement the task given below as a C++ program.

This program is for a car rental agency. Your program will have to compute the total cost of a rental. This agency has three types of cars, and the rates per day for rental are as follows:

All car rentals require a purchase of comprehensive insurance costing $15.00 per day and an initial one time bond payment of $100.00. Create an application that will ask for the type of car and the duration of car rental to calculate the cost of car rental.

You have to apply all the programming constructs that you have learned so far, as needed, to complete this exercise. (decisions, loops, input validation)

Sample Run 1:

Enter type of car: 2

Enter days of rental: 5

Cost of rental for 5 days is $ 450.00


1
Expert's answer
2021-10-01T03:54:51-0400
#include<iostream>
using namespace std;
int main(){
	int type;
	cout<<"Enter type of car:\n";
	cin>>type;
	while(type<0){
		cout<<"Invalid type of car entered.\nEnter type of car:  ";
		cin>>type;
	}
	int day;
	
	cout<<"Enter days of rental:\n";
	cin>>day;
	while(day<0){
		cout<<"Invalid number of days.\nEnter days of rental";
		cin>>day;
	}
	
	int total;
	if(type == 1){
		total = 100 + (40 + 15) * day;
		cout<<"Cost of rental for "<<day<<" days is $ "<<total<<endl; 
	}
	else if(type==2){
			total = 100 + (55 + 15) * day;
			cout<<"Cost of rental for "<<day<<" days is $ "<<total<<endl; 
	}
	else if(type==3){
			total = 100 + (70+ 15) * day;
			cout<<"Cost of rental for "<<day<<" days is $ "<<total<<endl; 
	}
	else{
		cout<<"Invalid car type\n";
	}
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS