# Thread: Help - Car Rite Rental (extra credit)

1. ## Help - Car Rite Rental (extra credit)

I am taking an intro to c++ class and this is extra credit for my test...Why won't this program work!!
Code:
```//Car Rite Rental
//By Mallory Mourot
//Extra Credit for Test One- Oct 19
#include <iostream>
using namespace std;

int main()
{
//definition of variables
char carType; char paymentOption;
int number; double total;
const double CdailyRate=30;
const double PdailyRate=40;
const double FdailyRate=50;
const double CmileRate=0.25;
const double PmileRate=0.35;
const double FmileRate=0.45;

//start up of program to gain input values carType, paymentOption
cout<<"Thank you for choosing Car Rite Rental for your rental needs!\n"
<<"\a Before we get started calculating your total owed please remember\n"
<<"that here at Car Rite Rental we havea MINIMUM PAYMENT OF \$30.\n\n"
<<"First let's determine what type of car you have rented: \n\n"
<<"[please enter corresponding letter] \n"
<<"C-Chevrolet\n"<<"P-Pontiac\n"<<"F-ford\n";
cin>>carType;
cout<<"Please choose your payment option from the following: \n\n"
<<"[please enter corresponding number] \n"
<<"D-Daily Rate\n"<<"M-Mileage Rate\n";
cin>>paymentOption;
//determine the number of miles or days
if(paymentOption=='D'||'d')
cout<<"Please enter the number of days you have rented this vehicle: \n";
else
cout<<"Please enter the number of miles traveled in your rental car:\n";
cin>>number;
//final step of putting all the information together and getting a total owed
if((carType=='C'||'c') && (paymentOption=='D'||'d'))
{
total=CdailyRate*number;
cout<<"Your total owed today is: \$"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
}
else if((carType=='C'||'c') && (paymentOption=='M'||'m'))
{
total=CmileRate*number;
if(total>=30)
cout<<"Your total owed today is: \$"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
else
cout<<"Your total owed today is: \$30.00\n"<<"Thank you again for choosing Car Rite Rental!\n";
}
else if((carType=='P'||'p') && (paymentOption=='D'||'d'))
{
total=PdailyRate*number;
cout<<"Your total owed today is: \$"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
}
else if((carType=='P'||'p') && (paymentOption=='M'||'m'))
{
total=PmileRate*number;
if(total>=30)
cout<<"Your total owed today is: \$"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
else
cout<<"Your total owed today is: \$30.00\n"<<"Thank you again for choosing Car Rite Rental!\n";
}
else if((carType=='F'||'f') && (paymentOption=='D'||'d'))
{
total=FdailyRate*number;
cout<<"Your total owed today is: \$"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
}
else if((carType=='F'||'f') && (paymentOption=='M'||'m'))
{
total=FmileRate*number;
if(total>=30)
cout<<"Your total owed today is: \$"<<total<<"\nThank you again for choosing Car Rite Rental!\n";
else
cout<<"Your total owed today is: \$30.00\n"<<"Thank you again for choosing Car Rite Rental!\n";
}
else
cout<<"You have entered a number choice that was invalid!"<<endl;

return 0;
}```

2. What seems to be wrong with it?

3. Code:
`else if((carType=='F'||'f') && (paymentOption=='D'||'d'))`
You can't do compound boolean statements like that. Must be

Code:
`else if((carType=='F'|| carType == 'f') && (paymentOption=='D'|| paymentOption == 'd'))`
Alternatively you can convert the input to lower case with tolower(); right after you read it, and use that to eliminate those compound booleans.

4. I also need to add a statement after the user chooses the car type. If the user does not enter one of the correct letter choices.
"you have entered the wrong code" and then the program is to end. I have tried using another if/ else statement using the exit(0) function to end the statement if the if statement is true but even when I put in the correct letter if it ending the program

5. Well, being extra credit, what exactly have you tried? There are many ways to do this, what have you learned already? Do you know switch statements? Based on your other problems my bet would be that your if statement that you tried didn't work based on a boolean logic problem.

6. Code:
```    if(paymentOption=='D'||'d')
cout<<"Please enter the number of days you have rented this vehicle: \n";
else
cout<<"Please enter the number of miles traveled in your rental car:\n";
cin>>number;```
Indentation mismatch? If so, fix the indentation.
Or is it you forget that two or more lines under some if statement must use braces?

Popular pages Recent additions