Hello rayjred,
QUOTE(rayjred @ 2 Aug, 2008 - 12:35 PM)

Here is my homework question, just looking to see if I'm on the right track and may be some pointers:
Weekly Rates
Hall Room Internet TV
Brown 800.00 50 20
Carlton 1000.00 50 20
Dalton 1500.00 80 20
Write a program that will prompt the user for the following:
Type of Hall?
Number of weeks of stay
Whether or not Internet access is required
Whether or not TV access is required
cpp
cout << endl << endl << "Enter the weekly room rate:";
cin >> weekly_room_rate;
According to the specification you posted you don't need to prompt for the weekly rate. It's a constant based on the Hall the user wants. You'll need to prompt for that. You should probably code something like...
cpp
const double BROWN_HALL_ROOMRATE = 800.00;
const double CARLTON_HALL_ROOMRATE = 1000.00;
const double DALTON_HALL_ROOMRATE = 1500.00;
const double BROWN_HALL_TVRATE = 50.00;
// etc...
And instead of get, use getline though if you just want to prompt for yes or no the whole word yes isn't really needed. Just use Yy or Nn or even simpler 0 and 1.
I'm assuming the data isn't going to be read from a file since the spec didn't mention this. But you could store the data read it into a vector of structures. Probably a little beyond the scope of the assignment at this point though.
When ever I do user input I create a couple of functions that pair up in a do while loop. Like the following...
cpp
do{
choice = get_choice("Press 1 to continue entering data or 0 to quit: ");
}while(!is_valid_choice( choice, 0, 1));
/////////////////////////
/// \fn get_choice( const string& prompt )
/// \brief Check to see if user wants to continue
///
/// \b SideEffects: None\n
/// \b Output: Prompts user to continue program\n
///
/// \return integer of choice entered by user
/////////////////////////
int get_choice( const string& prompt )
{
int ret_val =-1;
stringstream ioConv;
ioConv << get_string(prompt, 1024);
if(ioConv)
ioConv >> ret_val;
return ret_val;
}
/////////////////////////
/// \fn is_valid_choice( int val, size_t min, size_t max )
/// \brief Checks for valid entry for menu
///
/// \b SideEffects : None\n
/// \b Output : Displays an error message if an invalid choice is passed \n
///
/// \param val - Current choice from menu
/// \param min - minimum acceptable value
/// \param max - maximum acceptable value
///
/// \return boolean true if choice is valid and false otherwise
////////////////////////
bool is_valid_choice( unsigned int val, size_t min, size_t max )
{
bool ret_val = false;
if( val >= min && val <= max )
{
ret_val = true;
}
if(!ret_val){
cout << "Error: Invalid choice " << val << " selected." << endl;
}
return ret_val;
}
/////////////////////////
/// \fn get_string( const string& prompt, int maxSize )
/// \brief Gets a user entered string
///
/// \b SideEffects: None\n
/// \b Output: Prompts user to enter in string data\n
///
/// \param prompt - Display string that tells user what type of data string to enter
/// \param maxSize - maximum string size
///
/// \return ret_val - User entered string
/////////////////////////
string get_string( const string& prompt, int maxSize )
{
string ret_val;
cout << prompt;
getline(cin,ret_val);
return ret_val;
}
Entering in anything but 1 or 0 will continue the loop... I'd probably use 1 2 & 3 for the Halls instead of asking the user to enter in the name. Say..
cpp
do{
choice = get_choice("Which Hall are you staying in (0=Brown, 1=Carlton, 2=Dalton) ? ");
}while(!is_valid_choice( choice, 0, 2) );
// Add Loop to get number of weeks
// Add Loop to get tv
// Add Loop to get internet
Instead of all the if else blocks I probably use a switch statement....
cpp
switch ( choice ){
// Brown Hall
case 0: // Do calculations for Brown hall
rate = BROWN_HALL_ROOMRATE;
if( tv ) rate+= BROWN_HALL_TVRATE;
if( internet ) rate+= BROWN_HALL_INTERNETRATE;
break;
case 1: // Next hall etc....
}
total = rate * weeks;
Hope this helps...
JW