My final program and a logic error?

  • From: Jes <theeternalkid@xxxxxxxxx>
  • To: programmingblind@xxxxxxxxxxxxx
  • Date: Mon, 26 Jul 2010 07:36:04 -0400

Hi guys,

I'm supposed to ask my user if they want to continue running my program. If so, 
press y. if not, press n. The case of the response, I.E. whether the letter y 
or n is capitalized shouldn't matter. However, every time I press capital N, or 
any other letter for that matter, the computer interprets it as a y. How can I 
get the program to only accept responses from those two letters? Also, would 
someone be so kind as to take a quick peak at my code and see if it's sloppy or 
if I can make it more efficient? Bare in mind it's not all the way done yet.
Thanks.
*code**
//Final Project
//Created/revised by Jes Smith on July 20, 2010
#include <iostream>
#include <string>
using std::string;
using std::cout;
using std::cin;
using std::endl;
//Declare function proto types:
double RoomTotal(int, int, int);
char displayInformation(int, int, int);
int days(int, int);
double RoomTax(int, int);
int main()
{
        //declare variables
char userResponse = ' ';
//userResponse asks user if he/she wants to continue running the program. If 
user types n, no matter the caps,
//The program ends.
int RoomType = 0;
//RoomType displays type of room to user to make sure they selected correct 
room.
char currency = ' ';
//currency allows selection of current price in either American dollars or 
Mexican pesos, (A or P) by user.
int gt = ' ';
double gtp = 15.00;
//gt (ground transportation) based on y or n by user, if they want ground 
transportation to and from resort. gtp ground transportation price, constant 
cannot be changed, $15.00
int gtdays = 0;
char bt = ' ';
//bus tour = y or n
int nights = 0;
//nights number of nights user will stay at resort. Must be greater than 0.
int GetFinalTotal = 0;
//calculates final total after all values have been entered and displays to 
user at end of program before confirmation.

cout<< "Do you want to continue running this program? Please answer y/n) and 
press enter: ";
cin >> userResponse;
while (tolower(userResponse != 'n'))
{
cout << "Welcome to the CanCoon Mexican resort. ";
//}
system("cls");
cout << "What type of room would you like to reserve? \n ";
cout << "1. King Suite ($280.00) ";
cout << "2. Queen Beds Suite ($310.00) ";
cout << "3.  King Standard Room ($235.00) ";
cout << "4.  2 Queen Beds Standard Room ($255.00). \n Enter a choice now, then 
press enter to select. ";
cin >>RoomType;
switch (RoomType)
{
case 1:
cout<< "        King Suite ($280.00.) ";
break;
case 2:
cout << "2. Queen Beds Suite ($310.00) ";
break;
case 3:
cout << "King Standard Room ($235.00) ";
break;
case 4:
cout << "4. Queen Beds Standard Room ($255.00) ";
break;
default:

cout << "You entered an invalid response! Here are the choices again. Select 
your room from the following choices and press enter! ";
cout << "1. King Suite ($280.00) ";
cout << "2. Queen Beds Suite ($310.00) ";
cout << "3.  King Standard Room ($235.00) ";
cout << "4.  2 Queen Beds Standard Room ($255.00). \n Enter a choice now, then 
press enter to select. " "Which room would you like? ";
cin >> RoomType;
} //end switch
//cin >> RoomType;
cout << "How many nights will you be staying? (Must be greater than 0: " << 
endl;
cin >> nights;
if (nights <= 0)
{
        cout << "You entered 0. Your number must be greater than 0! Try again. 
\n How many nights will you be staying? ";
cin >> nights;
} //end if
cout << "You have selected to stay for "; cout << nights; cout << "nights. ";
cout << "Please press control C now to quit this program. ";
} //end while
return 0;
} //end of main function

Other related posts: