Help - Car Rite Rental (extra credit)

This is a discussion on Help - Car Rite Rental (extra credit) within the C++ Programming forums, part of the General Programming Boards category; I am taking an intro to c++ class and this is extra credit for my test...Why won't this program work!! ...

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    2

    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. #2
    Here we go again...
    Join Date
    Sep 2011
    Location
    San Diego
    Posts
    102
    What seems to be wrong with it?

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    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. #4
    Registered User
    Join Date
    Oct 2011
    Posts
    2
    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. #5
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    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.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #6
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,413
    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?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Credit Reports
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 09-10-2003, 12:53 AM
  2. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 03-31-2003, 11:23 PM
  3. Accepting Credit Cards
    By Mattman in forum C++ Programming
    Replies: 4
    Last Post: 03-17-2003, 02:55 PM
  4. Please help me with this Extra Credit program
    By DenisGFX in forum C Programming
    Replies: 10
    Last Post: 05-19-2002, 01:48 AM
  5. Deserving Credit
    By golfinguy4 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-02-2002, 01:50 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21