-
C++ programming
I am clueless on this stuff, can someone help me on my if statements? Cant get it to calculate the roomrates.. help??????
//Compiler directives
#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 (type == presidential)
{
roomRate = (695.00 * nights);
}
else if (type == "honeymoon")
{
roomRate = (295.00 * nights);
}
else if (type == "regular")
{
roomRate = (79.00 * nights);
}
else
roomRate = 0;
return roomRate;
}
-
I may not be programming in C++ at the moment ...
but i think you should ...
double findRoomRate(string type)
{
double roomRate = 0;
int nights = 0; // Set the nights to 1 instead of 0, 0 * 1 is still 0
double totalBill = 0;
if (type == "presidential")
{
roomRate = (695.00 * nights);
}
else if (type == "honeymoon")
{
roomRate = (295.00 * nights);
}
else if (type == "regular")
{
roomRate = (79.00 * nights);
}
else
roomRate = 0;
return roomRate;
}
or even simpler..
double findRoomRate(string type)
{
double roomRate = 0;
if (type == "presidential")
{
roomRate = 695.00;
}
else if (type == "honeymoon")
{
roomRate = 295.00;
}
else if (type == "regular")
{
roomRate = 79.00;
}
else
roomRate = 0;
return roomRate;
}
Last edited by Lameth; 10-25-2001 at 12:13 AM.
-
since you are using strings i donto think that cin works(at least with my compiler)...well you must uce the string command cin.getline()
and dont forget to put presidential into quotes so that the compiler does not think that it is a variable because it is a string
Popular pages
Recent additions