Hey guys brand new to C++ programming and I've been given the task of creating a car rental program which I've programmed a bit of it but I can't figure out how to implement the total charges given all the conditions and how to suggest an upgrade.
Here is the break down of the project:
1. Develop a program that calculates the cost of a car rental. The cost of the car is determined by the base price, whether the car is standard, old or premium and number of days and miles to be driven. The rental fees are structured as follows:
Car Base Price Additional Fees
A
$29.95
10 cents per mile
B
$35.95
15 cents per mile.
C
$39.95
20 cents per mile
Additionally, the user will enter a code to indicate if the car is to be Standard (S), Premium (P) or Old (O). Standard cars are billed at the rates quoted above. Premium cars are billed at the rate above with a 10% surcharge on the entire price. Old cars are billed at a 10% discount on the entire price.
2. This software is a "what if" price quote producer, so the user can continue to ask for quotes and see results until entering the letter "n" (not case sensitive)
3. The program will require some validity checking:
•
The user is required to enter a single character to represent the car chosen (A, B, or C) and then the S, P, or O choice. The program will continue to prompt the user until a valid car and then condition is entered. Assume the user will only enter a single character; there is no need to error check for entries of multiple characters.
•
The user is required to enter the number of miles to be driven and the number of days of the rental; these numbers must be greater than 0. If a negative number is entered the program provides a message and prompts the user to try again. Assume the user will only enter integers, there is no need to error check for letters or decimal values.
4. The program will try to sell the user the next more expensive car if S or O is entered, by quoting the charge for the next more expensive car less a 5% discount on the entire price. For example, if the user asked for an 'O' quote, the upgrade is to 'S.' If the user asked for an 'S' quote, the upgrade is to 'P.' No upgrade from 'P' is possible.
Welcome to the forums. The assignment pretty much speaks for itself. I don't think you need to write much code which you haven't used already elsewhere in the program:
The program will try to sell the user the next more expensive car if S or O is entered, by quoting the charge for the next more expensive car less a 5% discount on the entire price. For example, if the user asked for an 'O' quote, the upgrade is to 'S.' If the user asked for an 'S' quote, the upgrade is to 'P.'
char upgrade = 'O'; //upgrade can only be P or S, so O will be the "no upgrade" value
switch (condition)
{
case'S':
cout << "You chose standard." << endl;
char upgrade = 'P';
break;
case'O':
cout << "You chose old." << endl;
char upgrade = 'S';
break;
case'P':
cout << "You chose premium." << endl;
break;
default:
cout << "Invalid entry. Please enter S, O, or P." << endl;
cin >> condition;
}
//...
switch (upgrade)
{
case'P':
std::cout << "Would you like to upgrade to a premium car?";
break;
case'S':
std::cout << "Would you like to upgrade to a standard car?";
break;
}
I can't figure out how to implement the total charges given all the conditions
Easiest thing to do is to keep a variable such as double total_price=0; throughout the program. In every condition you increment or decrement this total with the right amount.
Please do let us know if you require any further help.
Ok SO I updated this with coding for the upgrade sections:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace std;
But I'm getting these errors:
clees-p2.cpp:69:15: error: jump to case label [-fpermissive]
clees-p2.cpp:66:18: error: crosses initialization of 'char upgrade'
clees-p2.cpp:71:18: error: redeclaration of 'char upgrade'
clees-p2.cpp:66:18: error: 'char upgrade' previously declared here
clees-p2.cpp:74:15: error: jump to case label [-fpermissive]
clees-p2.cpp:66:18: error: crosses initialization of 'char upgrade'
clees-p2.cpp:78:10: error: jump to case label [-fpermissive]
clees-p2.cpp:66:18: error: crosses initialization of 'char upgrade'
I also do not fully understand what you meant by keeping a variable as [code]double total_price = 0;
Are you referring to making each input answer total_price = the criteria that they've input so that it plugs in the adjacent formula or? Very confused sorry.
char upgrade; //declare the variable here
switch (condition)
{
case'S':
cout << "You chose standard." << endl;
upgrade = 'P'; //assign a value to it here
break;
case'O':
cout << "You chose old." << endl;
upgrade = 'S'; //assign a value to it here
break;
case'P':
cout << "You chose premium." << endl;
break;
default:
cout << "Invalid entry. Please enter S, O, or P." << endl;
cin >> condition;
}
I also do not fully understand what you meant by keeping a variable as double total_price = 0;
You need to declare a variable at the top of your main() function: total_price. Then, in every conditional statement (in your case, switch statements) you can update the total price. Simplified:
1 2 3 4 5 6 7 8 9
double total_price = 0;
if (car_type = 'a')
total_price += car_a_price;
//...
if (condition ='p')
total_price += condition_p_price;