program to calculate hotel stay

Hey I'm stuck on step 6. I cant seem to make the code actually do what its supposed to do.

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  /// This program that calculates the total cost of a hotel stay.

///The daily base charge is as follow:
/// Deluxe Double Room      $250
/// Deluxe Room      		$200
/// Standard Room   		$150

/// The hotel also charges for the following optional daily services:
/// Parking	                    $20 per day
/// High-speed internet	        $10 per day
/// Long distance phone calls	$15 per day


#include <iostream>
using namespace std;


/// Function prototypes here



int main()
{


	/// Variables
	int days;				  /// To hold the number of days
	int roomType;             /// To hold the room type
	double roomPerDay;        /// To hold the daily room charge

	double stayCharges;		  /// To hold the base charges
	double serviceCharge;     /// To hold the service charges
    double totalCharges;	  /// To hold the total charges

	char Parking;	          /// To hold Parking fees
    char H_S_internet;	      /// To hold High-speed internet fees
    char phoneCalls;	      /// To hold the phone calls fees

    double parkingCost;       /// To hold total parking cost
    double internetCost;      /// To hold total internet cost
    double phoneCost;         /// To hold total phone cost




	/// step 1:
	/// prompt the user for the required number of days.
    do{
        cout << "How many days do you want to spend in the hotel? ";
        cin >> days;

	/// step 2:
	///Check if the number of days is greater than 1.
    if (days < 1)
    {
       cout << "Please enter a valid number." << endl;
    }
    else
        break;
    }while (days >= 1);

    /// step 3:
	/// Prompt the user to choose the room-type.
	///The user will input 1 for Deluxe Double Room
	///The user will input 2 for Double Room
	///The user will input 3 for Standard Room.
    do {
        cout << "Please choose the room from the following options: " << endl;
        cout << "Enter 1 for the Deluxe Double Room. " << endl;
        cout << "Enter 2 for the Double Room. " << endl;
        cout << "Enter 3 for the Standard Room. " << endl;
        cin >> roomType;

    /// step 4:
    /// Validate the room-type. Check if the room-type is between 1 and 3.
    /// If the room-type is not within the acceptable range, ask the user for the room-type REPEATEDLY
    /// until the user enters a valid number.
    if (roomType < 1 || roomType > 3)
    {
       cout << "Please enter a valid number." << endl;
    }
    else
        break;
    }while (roomType >= 1 || roomType <= 3);

    /// step 5:
    /// if room-type = 1, then set roomPerDay = 250
    /// if room-type = 2, then set roomPerDay = 200
    /// if room-type = 3, then set roomPerDay = 150
    switch (roomType)
    {
    case 1:
        roomPerDay = 250;
        break;
    case 2:
        roomPerDay = 200;
        break;
    case 3:
        roomPerDay = 150;
        break;
    default:
        return 1;
    }

    cout << "Enter 'Y' for yes or 'N' for no for the following optional services: " << endl;
    /// step 6:
    /// Ask the user to enter Y or N if he/she wants a parking spot.
    /// These services will be for extra charge ($20 per day).
    /// If the user entered Y, then Parking = 20.
    /// If the user entered N, then Parking = 0.
    /// If the user entered any other char (Invalid char), REPEATEDLY ask the user again and again
    /// until the users enter a valid char
    do{
    cout << "Do you want a parking spot during your stay? ";
    cin >> Parking;
    if (Parking == 'Y' || Parking == 'y')
    {
        parkingCost=20*days;
        break;
    }
    if (Parking == 'N' || Parking == 'n')
    {
        parkingCost=0;
        break;
    }
    else
    {
    cout << "You entered an invalid answer. Please enter 'Y' for yes or 'N' for no. " << endl;
    }}
    while (Parking == 'Y' && Parking == 'y' && Parking == 'N' && Parking == 'n');

    /// step 7:
    /// Ask the user to enter Y or N if he/she wants High Speed Internet.
    /// These services will be for extra charge ($10 per day).
    /// If the user entered Y, then H_S_internet = 10.
    /// If the user entered N, then H_S_internet = 0.
    /// If the user entered any other char (Invalid char), REPEATEDLY ask the user again and again
    /// until the users enter a valid char



    /// step 8:
    /// Ask the user to enter Y or N if he/she wants Long Distance Calls
    /// These services will be for extra charge ($15 per day).
    /// If the user entered Y, then phoneCalls = 15.
    /// If the user entered N, then phoneCalls = 0.
    /// If the user entered any other char (Invalid char), REPEATEDLY ask the user again and again
    /// until the users enter a valid char




    /// step 10:
	/// Call the function calcStayCharges() to calculate the base charges.


	/// step 12:
	/// Call the function serviceCharge() to calculate the optional services charges.


	/// step 14:
	/// Call the function totalCharges() to calculate the Total charges.



    /// step 15:
	/// Display results on screen.


	return 0;
}



/// step 9:
/// write the calcStayCharges function
/// The calcStayCharges function accepts the number of days
/// spent at the hotel and the base charge for each day.
/// It calculates and returns the base charges as follow:
/// Base Charges = Number of days * charge per day





/// step 11:
/// write the calcServiceCharges function
/// The calcServiceCharges function calculates and returns the
/// total of the optional services (parking, internet, and long distance calls)
/// Services-Charge = Number of days * (Parking + H_S_internet + phoneCalls)




/// step 13
/// write the calcTotalCharges function
/// The calcTotalCharges function calculates and
/// returns the total charges as follow:
/// Total Charges = Base Charges + Services-Charge.
while (Parking != 'Y' && Parking != 'y' && Parking != 'N' && Parking != 'n')
Since user has to input when it's not one of the 4 characters.
when I do that i get an endless loop.
hey so this is what I have so far and I cannot seem to get my loops to work correctly. I would greatly appreciate any help.
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/// This program that calculates the total cost of a hotel stay.

///The daily base charge is as follow:
/// Deluxe Double Room      $250
/// Deluxe Room      		$200
/// Standard Room   		$150

/// The hotel also charges for the following optional daily services:
/// Parking	                    $20 per day
/// High-speed internet	        $10 per day
/// Long distance phone calls	$15 per day


#include <iostream>
using namespace std;


/// Function prototypes here
double calcBaseCharges (double days, double roomType)
double calcServiceCharge (double parkingCost, double internetCost, double phoneCost, double days)
double calcTotalCharges (double baseCharges, double serviceCharges)

int main()
{
	/// Variables
	int days;				  /// To hold the number of days
	int roomType;             /// To hold the room type
	double roomPerDay;        /// To hold the daily room charge

	double baseCharges;		  /// To hold the base charges
	double serviceCharges;     /// To hold the service charges
    double totalCharges;	  /// To hold the total charges

	char Parking;	          /// To hold Parking fees
    char internet;	          /// To hold High-speed internet fees
    char phoneCalls;	      /// To hold the phone calls fees

    double parkingCost;       /// To hold total parking cost
    double internetCost;      /// To hold total internet cost
    double phoneCost;         /// To hold total phone cost

	/// step 1:
	/// prompt the user for the required number of days.
    do{
        cout << "How many days do you want to spend in the hotel? ";
        cin >> days;

	/// step 2:
	///Check if the number of days is greater than 1.
    if (days < 1)
    {
       cout << "Please enter a valid number." << endl;
    }
    else
        break;
    }while (days >= 1);

    /// step 3:
	/// Prompt the user to choose the room-type.
	///The user will input 1 for Deluxe Double Room
	///The user will input 2 for Double Room
	///The user will input 3 for Standard Room.
    do {
        cout << "Please choose the room from the following options: " << endl;
        cout << "Enter 1 for the Deluxe Double Room. " << endl;
        cout << "Enter 2 for the Double Room. " << endl;
        cout << "Enter 3 for the Standard Room. " << endl;
        cin >> roomType;

    /// step 4:
    /// Validate the room-type. Check if the room-type is between 1 and 3.
    /// If the room-type is not within the acceptable range, ask the user for the room-type REPEATEDLY
    /// until the user enters a valid number.
    if (roomType < 1 || roomType > 3)
    {
       cout << "Please enter a valid number." << endl;
    }
    else
        break;
    }while (roomType >= 1 || roomType <= 3);

    /// step 5:
    /// if room-type = 1, then set roomPerDay = 250
    /// if room-type = 2, then set roomPerDay = 200
    /// if room-type = 3, then set roomPerDay = 150
    switch (roomType)
    {
    case 1:
        roomPerDay = 250;
        break;
    case 2:
        roomPerDay = 200;
        break;
    case 3:
        roomPerDay = 150;
        break;
    default:
        return 1;
    }

    cout << "Enter 'Y' for yes or 'N' for no for the following optional services: " << endl;
    /// step 6:
    /// Ask the user to enter Y or N if he/she wants a parking spot.
    /// These services will be for extra charge ($20 per day).
    /// If the user entered Y, then Parking = 20.
    /// If the user entered N, then Parking = 0.
    /// If the user entered any other char (Invalid char), REPEATEDLY ask the user again and again
    /// until the users enter a valid char
    do{
        cout << "Do you want a parking spot during your stay? ";
        cin >> Parking;
    if (Parking == 'Y' || Parking == 'y')
    {
        parkingCost=20;
        break;
    }
    else if (Parking == 'N' || Parking == 'n')
    {
        parkingCost=0;
        break;
    }
    else
    {
        cout << "You entered an invalid answer. Please enter 'Y' for yes or 'N' for no. " << endl;
    }}
    while (Parking != 'Y' && Parking != 'y' && Parking != 'N' && Parking != 'n');

    /// step 7:
    /// Ask the user to enter Y or N if he/she wants High Speed Internet.
    /// These services will be for extra charge ($10 per day).
    /// If the user entered Y, then H_S_internet = 10.
    /// If the user entered N, then H_S_internet = 0.
    /// If the user entered any other char (Invalid char), REPEATEDLY ask the user again and again
    /// until the users enter a valid char
    do{
        cout << "Do you want a high speed internet during your stay? ";
        cin >> internet;
    if (internet == 'Y' || internet == 'y')
    {
        internetCost=10;
        break;
    }
    else if (internet == 'N' || internet == 'n')
    {
        internetCost=0;
        break;
    }
    else
    {
        cout << "You entered an invalid answer. Please enter 'Y' for yes or 'N' for no. " << endl;
    }}
    while (internet != 'Y' && internet != 'y' && internet != 'N' && internet != 'n');

    /// step 8:
    /// Ask the user to enter Y or N if he/she wants Long Distance Calls
    /// These services will be for extra charge ($15 per day).
    /// If the user entered Y, then phoneCalls = 15.
    /// If the user entered N, then phoneCalls = 0.
    /// If the user entered any other char (Invalid char), REPEATEDLY ask the user again and again
    /// until the users enter a valid char
    do{
        cout << "Do you want long distance call service during your stay? ";
        cin >> phoneCalls;
    if (phoneCalls == 'Y' || phoneCalls == 'y')
    {
        phoneCost=15;
        break;
    }
    else if (phoneCalls == 'N' || phoneCalls == 'n')
    {
        phoneCost=0;
        break;
    }
    else
    {
        cout << "You entered an invalid answer. Please enter 'Y' for yes or 'N' for no. " << endl;
    }}
    while (phoneCalls != 'Y' && phoneCalls != 'y' && phoneCalls != 'N' && phoneCalls != 'n');



    /// step 10:
	/// Call the function calcStayCharges() to calculate the base charges.
    calcBaseCharges(days,roomType);

	/// step 12:
	/// Call the function serviceCharge() to calculate the optional services charges.
    calcServiceCharge(parkingCost,internetCost,phoneCost,days);

	/// step 14:
	/// Call the function totalCharges() to calculate the Total charges.
    calcTotalCharges(baseCharges,serviceCharges)

    /// step 15:
	/// Display results on screen.
    cout << "The Total charges are $" << totalCharges << endl;
    cout << endl;

	return 0;
}



/// step 9:
/// write the calcStayCharges function
/// The calcStayCharges function accepts the number of days
/// spent at the hotel and the base charge for each day.
/// It calculates and returns the base charges as follow:
/// Base Charges = Number of days * charge per day
double calcBaseCharges (double days, double roomType)
{
baseCharges = days * roomType;
return baseCharges;
}

/// step 11:
/// write the calcServiceCharges function
/// The calcServiceCharges function calculates and returns the
/// total of the optional services (parking, internet, and long distance calls)
/// Services-Charge = Number of days * (Parking + H_S_internet + phoneCalls)
double calcServiceCharge (double parkingCost, double internetCost, double phoneCost, double days)
{
serviceCharges = days *(parkingCost + internetCost + phoneCost);
return serviceCharges;
}

/// step 13
/// write the calcTotalCharges function
/// The calcTotalCharges function calculates and
/// returns the total charges as follow:
/// Total Charges = Base Charges + Services-Charge.
double calcTotalCharges (double baseCharges, double serviceCharges)
{
totalCharges = baseCharges + serviceCharges;
return totalCharges;
}
I cannot seem to get my loops to work correctly
How do you know? Your code doesn’t compiles :-)

Anyway, the most of your loops are correct, only the first one is wrong:
while (roomType >= 1 || roomType <= 3);
It needs to loop as long as the user inserts wrong answers, not correct ones.

You missed a lot of semicolons - just read compiler warnings / errors: they can put you on the right track.

The biggest problem is you don’t catch the return values from your functions, so they are calculated, but they never get into main().

Other two points I think you should pay more attention to are:
1) don’t let any variable uninitialised (it’s not mandatory, but very helpful);
2) do not declare any variables until you really need it.

Hints:
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include <iostream>
#include <limits>

double calcBaseCharges (double days, double room_per_day);
double calcServiceCharge (double parkingCost, double internetCost,
                            double phoneCost, double days);
double calcTotalCharges (double baseCharges, double serviceCharges);
void waitForEnter();

int main()
{
    int days {};
    do {
        std::cout << "How many days do you want to spend in the hotel? ";
        std::cin >> days;

        if (days < 1) { std::cout << "Please enter a valid number.\n"; }
        else          { break; }
    } while (days < 1);

    int roomType {};
    do {
        std::cout << "Please choose the room from the following options:\n"
                     "Enter 1 for the Deluxe Double Room.\n"
                     "Enter 2 for the Double Room.\n"
                     "Enter 3 for the Standard Room.\n >> ";
        std::cin >> roomType;

        if (roomType < 1 || roomType > 3)
        {
            std::cout << "Please enter a valid number.\n";
        }
        else { break; }
    } while (roomType < 1 || 3 < roomType);

    double roomPerDay {};
    switch (roomType)
    {
    case 1:
        roomPerDay = 250;
        break;
    case 2:
        roomPerDay = 200;
        break;
    case 3:
        roomPerDay = 150;
        break;
    default:
        std::cout << "Room type error: please check the code.\nExiting now.\n";
        return 1;
    }

    std::cout << "Enter 'Y' for yes or 'N' for no for the following optional "
                 "services:\n";

    char Parking {};
    double parkingCost {};
    do {
        std::cout << "Do you want a parking spot during your stay? ";
        std::cin >> Parking;
        if (Parking == 'Y' || Parking == 'y') 
        {
            parkingCost = 20;
            break;
        }
        else if (Parking == 'N' || Parking == 'n')
        {
            parkingCost = 0;
            break;
        }
        else
        {
            std::cout << "You entered an invalid answer. Please enter 'Y' "
                         "for yes or 'N' for no.\n";
        }
    } while (   Parking != 'Y' && Parking != 'y'
             && Parking != 'N' && Parking != 'n');

    char internet {};
    double internetCost {};
    do {
        std::cout << "Do you want a high speed internet during your stay? ";
        std::cin >> internet;
        if (internet == 'Y' || internet == 'y')
        {
            internetCost = 10;
            break;
        }
        else if (internet == 'N' || internet == 'n')
        {
            internetCost = 0;
            break;
        }
        else
        {
            std::cout << "You entered an invalid answer. Please enter 'Y' "
                         "for yes or 'N' for no.\n";
        }
    } while (   internet != 'Y' && internet != 'y'
             && internet != 'N' && internet != 'n');

    char phoneCalls {};
    double phoneCost {};
    do {
        std::cout << "Do you want long distance call service during your stay? ";
        std::cin >> phoneCalls;
        if (phoneCalls == 'Y' || phoneCalls == 'y')
        {
            phoneCost = 15;
            break;
        }
        else if (phoneCalls == 'N' || phoneCalls == 'n')
        {
            phoneCost = 0;
            break;
        }
        else
        {
            std::cout << "You entered an invalid answer. Please enter 'Y' "
                         "for yes or 'N' for no.\n";
        }
    } while (   phoneCalls != 'Y' && phoneCalls != 'y'
             && phoneCalls != 'N' && phoneCalls != 'n');

    double baseCharges = calcBaseCharges(days, roomPerDay);
    double serviceCharges = calcServiceCharge(parkingCost, internetCost, phoneCost, days);
    double totalCharges = calcTotalCharges(baseCharges,serviceCharges);
    std::cout << "The Total charges are $ " << totalCharges << " \n\n";
    waitForEnter();
    return 0;
}

double calcBaseCharges (double days, double room_per_day)
{
    return days * room_per_day;
}

double calcServiceCharge (double parkingCost, double internetCost, 
                            double phoneCost, double days)
{
    return days * (parkingCost + internetCost + phoneCost);
}

double calcTotalCharges (double baseCharges, double serviceCharges)
{
    return baseCharges + serviceCharges;
}

void waitForEnter()
{
    std::cin.ignore(1000, '\n');
    std::cout << "\nPress ENTER to continue...\n";
    std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
}

Topic archived. No new replies allowed.