cout << Question << " Enter Y or N: ";
cin >> Choice;
Choice = toupper(Choice);
while (Choice != 'Y' && Choice != 'N')
{
cout << "Invalid character. Please enter either (Y) for yes or (N) for no.\n";
cout << Question << " Enter Y or N: ";
cin >> Choice;
Choice = toupper(Choice);
}
ParkingPassChoice = GetYorN ("Would you like to buy parking passes?");
if (ParkingPassChoice == 'Y')
{
cout << "Parking passes are $10 per day." << endl;
cout << "How many days of parking would you like to buy (1-"
<< MAX_DAYS_ALLOWED << "): ";
cin >> ParkingDays;
while(ParkingDays < 1 || ParkingDays > MAX_DAYS_ALLOWED)
{
cout << "Please enter a valid number of days (1-"
<< MAX_DAYS_ALLOWED << ") or enter 0 to cancel your purchase: ";
cin >> ParkingDays;
}
ParkingPassPrice = PARKING_PRICE_PER_DAY * ParkingDays;
}
cout << "\n--------------------------------------------------------------------------\n";
cout << "You have chosen to order " << noshowpoint << setprecision(0) << NumTickets
<< " " << TicketName << " tickets.\n";
cout << fixed << showpoint << setprecision(2);
cout << "Each ticket costs $" << PricePerTicket << ".\n";
cout << "The price for these tickets is $" << Amount << endl;
cout << "--------------------------------------------------------------------------\n\n";
return Amount;
}
//---------------------------------------------------------------------------
// Name: AddPremium
// Parameters: Price, float, input/output, current cost of the tickets
// It gets updated if the user selects the premium upgrade
// NumTickets, const int, input, the number of tickets.
// Returns: none
// Purpose: This function adds the cost of the premium upgrade, if the patron
// chooses to purchase it
//---------------------------------------------------------------------------
void AddPremium(float &Price, const int NumTickets)
{
char Choice;
cout << "\n----------------------------------------------------------------------------------------------\n";
cout << "You have chosen to order Box seat tickets.\n";
cout << "You can add a premium package that includes a souvenier and free refreshments.\n"
<< "This costs $" << PREMIUM_PRICE<< " per ticket.\n";
cout << "----------------------------------------------------------------------------------------------\n\n";
Choice = GetYorN("Would you like to add the premium package?");
//---------------------------------------------------------------------------
// Name: MainMenu
// Parameters: none
// Returns: none
// Purpose: This function prints the main menu describing various tickets
// offered by the Walton Arts Center
//---------------------------------------------------------------------------
void MainMenu()
{
char MoreInfo;
cout << "The Walton Arts Center offers its patrons an assortment\n"
<< "of tickets to fit different budgets.\n"
<< "There are three kinds of seats that the Arts Center offers:\n"
<< "Balcony, Orchestra, and Box seats.\n\n";
MoreInfo = GetYorN("Would you like more information about each ticket type?");
if(MoreInfo == 'Y')
{
cout << "The Balcony tickets are the cheapest, because the tickets"
<< " are located the furthest from stage.\n";
cout << "The Orchestra tickets are more expensive, because the tickets allow "
<< "participants to sit closer to the stage.\n";
cout << "The Box seat tickets are the most expensive, "
<< "because the seats are very comfortable and private.\n"
<< "Box seat purchasers can also add other options (souvenirs and refreshments)"
<< " to their purchase.\n\n";
}
}
//---------------------------------------------------------------------------
// Name: TicketType
// Parameters: none
// Returns: char; the selection of ticket to be purchased
// Purpose: This function asks the user which ticket they would like to buy
//---------------------------------------------------------------------------
char GetTicketType()
{
char TicketType;
cout << "\nWhich ticket would you like to purchase next?\n";
cout << "Type B for Balcony, O for Orchestra, or X for Box: ";
cin >> TicketType;
TicketType = toupper(TicketType); //convert to uppercase
//User I/O error-checking
while(TicketType != 'B' && TicketType != 'O' && TicketType != 'X')
{
cout << TicketType << " is invalid input.\n";
cout << "Type B for Balcony, O for Orchestra, or X for Box: ";
cin >> TicketType;
TicketType = toupper(TicketType);
}
return TicketType;
}
//---------------------------------------------------------------------------
// Name: GetNumTickets
// Parameters: NumTickets, integer, reference, passes back the number of tickets requested
// Returns: none
// Purpose: This function asks the user how many tickets would like to buy
//---------------------------------------------------------------------------
void GetNumTickets (int &NumTickets)
{
cout << "Enter the number of tickets you would like to buy: ";
cin >> NumTickets;
while(NumTickets < 0) //User I/O error-checking
{
cout << "Please enter a non-negative number of tickets: ";
cin >> NumTickets;
}
}
int main ()
{
// Variable Declarations
char Choice = '\0'; // what the user enters
int NumTickets = 0; // how many tickets they want to buy
float BPrice = 0.0; // the price of one set of tickets
float OPrice = 0.0;
float XPrice = 0.0;
float Total = 0.0; // the total price of all tickets
float Parking = 0.0;
// Print your name and UAID
cout << "My name is Matthew Lor and my UAID is 010245540" << endl;
// Loop until the user is done
// Print the main menu describing the tickets offered
MainMenu();
// Ask the user type what ticket they want to purchase next
do{
// Find out how many tickets they want
switch (GetTicketType()){
case 'B':
GetNumTickets(NumTickets);
BPrice = CalculatePrice ("Balcony", 25.00, NumTickets);
Choice = GetYorN("Will this be it?");
break;
case 'O':
GetNumTickets(NumTickets);
OPrice = CalculatePrice ("Orchestra", 50.00, NumTickets);
Choice = GetYorN("Will this be it?");
break;
case 'X':
GetNumTickets(NumTickets);
XPrice = CalculatePrice ("Box", 75.00, NumTickets);
AddPremium (XPrice, NumTickets);
Choice = GetYorN("Will this be it?");
break;}}
while (Choice == 'N');
// Find out the price of the tickets
// If the user selects Box seats, ask if they want the premium package
// Add the ticket price to a running total
// Ask if they want to continue (Y or N)
// When the loop is done
// Sell the user parking pass
Parking = ParkingPass();
// Print out the total amount of all the tickets and parking passes
Total = Parking + OPrice +BPrice + XPrice;
cout << "Your Total is: $" << Total << endl;
// that the participant has purchased to 2 decimal places, with a $