Thread: Help, I hate these if statements!!

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    3

    Angry Help, I hate these if statements!!

    I cant get the 2nd and 3rd if statements to work, only the presidental one displays. help?????

    #include <iostream> // Provides cin, cout, endl
    #include <string> // Provides string class
    using namespace std; // Provides standard library

    //Function Prototypes
    string getRoomType();
    int askRoomNights();
    double findRoomRate(string type);
    void displayBill(string type, int &nights, double &roomRate, double &totalBill);


    int main()
    {
    string type = ""; // Input - Room Type
    int nights = 0; // Input - Number of nights
    double roomRate = 0; // Processing - daily Room Rate
    double totalBill = 0; // Output - total room bill

    type = getRoomType(); // Ask user for room type

    nights = askRoomNights(); // Ask user for number of nights

    roomRate = findRoomRate(type); // Determine Room Rate

    totalBill = nights * roomRate; // Calculate total bill

    displayBill (type, nights, roomRate, totalBill);

    return 0;
    } // end main

    void displayBill(string type, int &nights, double &roomRate, double &totalBill)
    {

    cout << "HOTEL BILL" << endl;
    cout << type << " room for " << nights << " nights" << endl;
    cout << "daily rate =" << roomRate << " total bill is " << totalBill << endl;
    }


    string getRoomType()
    {
    string type = "";

    cout << "Enter desired Room Type(Presidential, Honeymoon or Regular) " << endl;
    cin >> type;


    return type;
    }

    int askRoomNights()
    {
    int nights = 0;

    cout << "Entered desired number of nights" << endl;
    cin >> nights;

    return nights;
    }

    double findRoomRate(string type)
    {

    double roomRate = 0;
    int nights = 0;
    double totalBill = 0;

    if ("Presidential")

    roomRate = 695.00;

    else if ("Honeymoon")

    roomRate = 295.00;

    else if ("Regular")

    roomRate = 79.00;

    else

    roomRate = 0;

    return roomRate;
    }

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    241
    well you need to have the string in the if statement = to something, and in c++ you have to use "==" instead of "="

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    28
    try -

    if (type == "presidential")
    more stuff


    also you could use a switch statement here.
    rc7j

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  3. Tabbed Windows with MDI?
    By willc0de4food in forum Windows Programming
    Replies: 25
    Last Post: 05-19-2005, 10:58 PM
  4. Pet Peeves
    By Srg Pepper in forum A Brief History of Cprogramming.com
    Replies: 29
    Last Post: 10-03-2002, 11:34 AM
  5. I hate string parsing with a passion
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-19-2002, 07:30 PM