Hotel Room Calculator. Output is incorrect?

I made this program to calculate hotel expenses. Everything works fine, except the output is rounded off as an integer, when it should be a double. For example, If the input is $225 for roomPrice, 14 for roomNum, 7 for roomDays, and 7.2 for salesTax, the output should be $20091.96. But instead, the output is $20092.

Why is it rounding and displaying as an int? I know it's something simple but I can't figure it out. Am I missing a header file or something?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
  #include <iostream>

using namespace std;

int main()
{
    double roomPrice;
    double roomNum;
    double roomDays;
    double total1;
    double total2;
    double discount;
    float salesTax;


    cout << "\t\t========  Hotel Booking Calculator!  ========" << endl << endl;

    cout << "Enter the price of one room: " << flush; //Promt the user to enter the information on the rooms
    cin >> roomPrice;

    cout << "How many rooms are being booked?: " << flush;
    cin >> roomNum;

    cout << "How many days will the rooms be booked for?: " << flush;
    cin >> roomDays;

    cout << "What is the sales tax?(as a percent): " << flush;
    cin >> salesTax;

    if (roomNum >= 10 && roomNum < 20){    // Calculate the discount by comparing days and rooms
        discount = 0.1;
    }
    else if (roomNum >= 20 && roomNum < 30){
        discount = 0.2;
    }
    else if (roomNum >= 30){
        discount = 0.3;
    }
    else {
        discount = 0;
    }

    if (roomDays >= 3){
        discount = discount + 0.05;
    }

    cout << "\n\nIndividual room price: $" << roomPrice << endl; // Display what the user entered
    cout << "Discount: " << discount * 100 << "%" << endl;
    cout << "Number of rooms: " << roomNum << endl;
    cout << "Number of days: " << roomDays << endl;
    cout << "Total cost of rooms(before discount and tax): $" << (roomNum * roomPrice) * roomDays << endl;
    cout << "Sales tax: " << salesTax << "%" << endl;

    total1 = (roomNum * roomPrice) * roomDays;

    total2 = total1 * discount;

    total1 = total1 - total2;

    salesTax = salesTax / 100;

    total2 = total1 * salesTax;

    total1 = total1 + total2;

    cout << "Total billing amount: $" << total1 << endl;

    return 0;
}
cout << "Total billing amount: $" << fixed << setprecision( 2 ) << total1 << endl;

You will need header
#include <iomanip>
in order to use setprecision.
Last edited on
Ahh, of course. *face palm*

Thanks man :)
Topic archived. No new replies allowed.