Void Function

Hello all!! Ive tried completing this problem but Im not sure how to use the void function. Also Ive had trouble using the if else statements with char

/// 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.
cout << "How many days do you want to stay in the hotel? ";
cin >> days;


/// step 2:
///Check if the number of days is greater than 1.
while (days<1)
{
cout << "How many days do you want to stay in the hotel? ";
cin >> days;
}




/// 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.
cout << "Please choose the room from the following options:";
cout << "\nFor Deluxe Double Room: Please enter 1";
cout << "\nFor Double Room: Please enter 2";
cout << "\nFor Standard Room: Please enter 3\n";
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.
while (roomType<1 || roomType>3)
{
cout << "Please choose the room from the following options:";
cout << "\nFor Deluxe Double Room: Please enter 1";
cout << "\nFor Double Room: Please enter 2";
cout << "\nFor Standard Room: Please enter 3\n";
cin >> roomType;

}



/// 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
if (roomType==1)
{
roomPerDay=250;
}
else if (roomType==2)
{
roomPerDay=200;
}
else if (roomType==3)
{
roomPerDay=150;
}


/// 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).
cout << "Enter 'Y' for yes and 'N' for no for the following optional services:";

/// 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
cout << "\nDo you want a parking spot during your stay?\n";
cin >> Parking;
if (Parking!='Y' || Parking!='N')
{
cout << "\nDo you want a parking spot during your stay?\n";
cin >> Parking;
}
else if (Parking=='Y')
{
parkingCost=20*days;
}
else if (Parking=='N')
{
parkingCost=0;
}



/// 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
cout << "\nDo you want High Speed Internet during your stay?\n";
cin >> H_S_internet;
if (H_S_internet!='Y' || H_S_internet!='N')
{
cout << "\nDo you want High Speed Internet during your stay?\n";
cin >> H_S_internet;
}
else if (H_S_internet=='Y')
{
internetCost=10*days;
}
else if (H_S_internet=='N')
{
internetCost=0;
}


/// 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
cout << "\nDo you want Long Distance Service during your stay?\n";
cin >> phoneCalls;
if (phoneCalls!='Y' || phoneCalls!='N')
{
cout << "\nDo you want Long Distance Service during your stay?\n";
cin >> phoneCalls;
}
else if (phoneCalls=='Y')
{
phoneCost=15*days;
}
else if (phoneCalls=='N')
{
phoneCost=0;
}




/// 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.
Last edited on
1) Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/

2) What void function? You don't have a void function anywhere in your code. Can you clarify what your problem is?

3)
Also Ive had trouble using the if else statements with char

Your logic is incorrect. Look at:

if (phoneCalls!='Y' || phoneCalls!='N')

Can you tell me any condition under which that would not be true?
Last edited on
If the user inputs something other than 'Y' or 'N' then it should repeat the question
OK. Now look at what you've actually written. Can you tell me under what circumstances the condition you've actually written will not be true?

Oh, and thankyou for completely ignoring two of the three things I asked you about. That totally convinces me that I should take helping you seriously.
Last edited on
Topic archived. No new replies allowed.