I need to write a program records membership fees for a Gym. The Gym charges a $1,200 per year, base fee but charges a percentage rate increase each year based on your membership rating:
Gold Members 1% fee
Silver Members 2% fee
Bronze Members 4% fee
It will display the following menu:
Welcome to Ronda’s Strikeforce Gym!!
x---------------------------------------------------x
Membership Fee Calculator
Gold
Silver
Bronze
Quit
Please enter your membership level (1-3 Enter 4 to Quit) >
The Validate input for the menu items listed, if 1 through 3 is entered, the program will use a loop to output the member's expected fees for the next 10 years. The output format is a table with the corresponding year and membership fee.
The program should continue to loop until the user is ready to quit. I am supposed to encapsulate the code in a do-while loop.
If a 4 is entered then the program should quit. Any other input should show an error message as output.
My output is not starting at the basevalue of 1200 but factors in the percentage. Upon another iteration of the program the last value calculated is used as a starting point.
This is what I have:
//Assignment 4-A.cpp: The program will calculate the membership fees over the next 10 years based on the membership level
#include <iostream>
#include <iomanip>
using namespace std;
int main() // Driver program
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
//To hold menu choice
const int GOLD = 1,
SILVER = 2,
BRONZE = 3,
QUIT = 4;
//To hold the percentage tax of the different gym choices
const double tax_gold = .01,
tax_silver = .02,
tax_bronze = .04;
//To hold the base charge per year
const double base_charge = 1200.00;
//variables
double fees = 0, cost = base_charge, cost_1 = 1200.00;
//To hold the users input
int user_input;
const int min_number = 1,
max_number = 10;
int i;
do
{
cout << "\t Welcome to Ronda's Strikeforce Gym!!" << endl; //Title
cout << "x";
for (int i = 0; i <= 50; i++) //Dashed line, row
{
cout << ("-");
}
cout << "x";
cout << endl;
cout << "\t Membership Fee Calculation" << endl; //Title
//Display of gym membership plan choice
cout << "1. Gold" << endl;
cout << "2. Silver" << endl;
cout << "3. Bronze" << endl;
cout << "4. Quit" << endl << "\n";
cout << "Please enter your membership level (1-3 Enter 4 to Quit) ";
cin >> user_input;
cout << endl;
// Validate user input(must input 1 through 4), loop if value is invalid
while (user_input < 1 || user_input > 4)
{
cout << "Invalid entry! ";
cout << "Please enter a selection from 1 through 4: ";
cin >> user_input;
cout << endl;
}
// If values 1 - 3 were entered perform calculations else if 4 was entered exit program with thank you message.
// Perform calculation for specified membership for 10 years and output
if (user_input == 4)
{
break;
}
if (user_input != QUIT)
{
//Start selection loop and calculation
switch (user_input)
{
case 1:
fees = base_charge * tax_gold;
cost = base_charge + fees;
break;
case 2:
fees = base_charge * tax_silver;
cost = base_charge + fees;
break;
case 3:
fees = base_charge * tax_bronze;
cost = base_charge + fees;
break;
}
//Display Yearly Cost
for (int years = 1; years <= 10; ++years)
{
cout << "Year " << years << "\t $" << (cost_1 += fees) << endl;
}
cout << "\n";
}
} while (user_input != QUIT);
{
cout << "Thank you for using Ronda's Fee Calculator! \n";
}
cout << endl;
cout << "Press any key to continue . . .";
return 0;
}
This is what shows on my computer:
enter image description here
and this is what it should look like:
enter image description here
Thank you
Your calculations should start with the base rate (cost = 1200). For each year, print the current rate then add rate * tax. (cost += cost * tax).
Here's your code with a few modifications:
//To hold menu choice
const int GOLD = 1, SILVER = 2, BRONZE = 3, QUIT = 4;
//To hold the percentage tax of the different gym choices
const std::array<double, 3> tax_rates{.01, .02, .04};
//To hold the base charge per year
const double base_charge = 1200.00;
while (true) {
cout << "\t Welcome to Ronda's Strikeforce Gym!!\nx"; //Title
for (int i = 0; i <= 50; i++) //Dashed line, row
{
cout << ("-");
}
cout << "x\n\t Membership Fee Calculation\n"; //Title
//Display of gym membership plan choice
cout << "1. Gold" << endl;
cout << "2. Silver" << endl;
cout << "3. Bronze" << endl;
cout << "4. Quit" << endl << "\n";
cout << "Please enter your membership level (1-3 Enter 4 to Quit) ";
int user_input;
cin >> user_input;
cout << endl;
// Validate user input(must input 1 through 4), loop if value is invalid
while (user_input < 1 || user_input > 4)
{
cout << "Invalid entry! ";
cout << "Please enter a selection from 1 through 4: ";
cin >> user_input;
cout << endl;
}
// If values 1 - 3 were entered perform calculations else if 4 was entered exit program with thank you message.
// Perform calculation for specified membership for 10 years and output
if (user_input == QUIT)
{
break;
}
//Display Yearly Cost
double cost = base_charge;
for (int years = 1; years <= 10; ++years)
{
cout << "Year " << years << "\t $" << cost << endl;
cost += cost * tax_rates[user_input-1];
}
cout << "\n";
}
cout << "Thank you for using Ronda's Fee Calculator!\n\nPress any key to continue . . .";
Side note: it is recommended that you don't use floating point values for currency. FP can introduce rounding errors. You can use integers in the base denomination of the currency. In US dollars that would be cents (pennies). Just something to note for future projects.
Related
This code is designed to take an order, add that to the total_price variable, apply discounts based on the total price, then add a tip and echo all the information back to the user.
For some reason when I run the code, it isn't taking input from the user. I think it's related to the while statement but it outputs that my total_price is 0 after entering integers.
The tip calculation at the bottom isn't working correctly. It prompts the user to enter a tip value, but then skips to the end and says the final total is 0, without the user being able to enter any tip.
Thanks so much for the help!!
#include <iostream>
using namespace std;
int main()
{
int total_price{0}; // This variable will contain the price for all orders
int tip{0};
int discount_total{0};
int tip_total = tip + discount_total;
cout << "Welcome!\nThis program is designed to help take your order.\n";
cout << "Our discounts availible today are: \n10 percent off orders over $50, and 5 percent off orders between $25 and $50.\n";
// This is where the user is prompted to enter the price of their order
cout << "Please enter the price of your item: ";
cin >> total_price;
// No negative numbers will be accepted
if (total_price <= 0)
{
cout << "Invalid number, please re-enter the price of your item: ";
}
// User can continue ordering unless typing No
while (total_price > 0)
{
cout << "Is there anything else? If not type No: ";
cin >> total_price;
}
// Once the user types No, it brings them to the tip section
// Marks the end of the order
if ("No")
{
cout << "Thank you. Your total price is " << total_price << endl;
}
// Discount modifications
if (total_price >= 50)
{
discount_total = total_price * .05;
cout << "Your new total is " << discount_total << " with the 10 percent discount.\n";
}
else if (total_price >= 25 && total_price <= 50)
{
discount_total = total_price * .05;
cout << "Your new total is " << total_price << " with the 5 percent discount.\n";
}
else
{
total_price = discount_total;
cout << "Your total is the same, " << total_price << "\n";
}
// Tip calculation
cout << " Feel free to add a tip! Please enter here: ";
cin >> tip;
if (tip > 0)
{
cout << "Your final total is: " << tip_total << " dollars";
}
else if (tip < 0)
{
cout << "Your tip is invalid, please enter a valid tip: ";
}
return 0;
}
Hello I'm here as a last resort. For this assignment, I have been unable to figure out certain things like how to show a decimal as a whole number. For example, .29 should be 29.00. I also don't know how to show the number of items properly as in if there's 2 items(3 eggs and 2 cheeses),how do I only show 2 items instead of 5?
I have attached the guidelines for this assignment and what I have so far. Thank you for your help!
Part A
Your program should obtain the following information from the user upon startup:
• Name of the cashier.
• State that store is located in (Arizona, New York, etc)
• Date (separated into day, month and year)
Part B
The program should display a welcome message to the user in the following format:
Hello (cashier name) Welcome to Cashier App.
You are currently cashing for a store located in (state).
Today’s date is (date).
The program should allow the user to enter, for an unlimited number of products, the name of the product, the price and the quantity being purchased. The program must calculate the amount of tax to add to the price, depending on which of the following three states the program is being used in:
New York - 9.75%
New Jersey - 8.25%
Connecticut - 7.5%
Tennessee - 4.5%
All Others - 10%
After calculating the total amount owed for a single product, the program should display the name of the product and the total and then ask the user whether or not they would like to enter another product i.e.
Eggs - $10.74
Would you like to enter another product?
After the user has entered all of their products, you should display a summary of the purchases that tells the user how many items were entered and the total amount due i.e.
You have entered 14 products. Your total amount owed is $845.89
#include <iostream>
using namespace std;
int main() {
string state, month, day, year, cashierName, productName;
char YorN;
float price, tax, productTotal, productQuantity, totalQuantity = 0, total = 0;
cout << "Enter name: ";
cin >> cashierName;
cout << "Are you in NY, NJ, CT, TN, or other?: ";
cin >> state;
cout << "Enter month: ";
cin >> month;
cout << "Enter day: ";
cin >> day;
cout << "Enter year: ";
cin >> year;
cout << "Hello " << cashierName << ". Welcome to Cashier App.\n";
cout << "You are currently cashing for a store located in " << state << ".\n";
cout << "Today's date is " << month << " " << day << ", " << year << ".\n";
if(state == "NY" || state == "ny") {
tax = .0975;
}
else if (state == "NJ" || state == "nj") {
tax = .0825;
}
else if (state == "CT" || state == "ct") {
tax = .075;
}
else if (state == "TN" || state == "tn") {
tax = .045;
}
else {
tax = .1;
}
cout << "Do you want to add a product to your cart? (Y/N) ";
cin >> YorN;
while(YorN == 'Y' || YorN == 'y') {
cout << "Enter product name: ";
cin >> productName;
cout << "Enter price: ";
cin >> price;
cout << "Enter quantity: ";
cin >> productQuantity;
productTotal = price * productQuantity * tax;
total = productTotal + total;
totalQuantity = productQuantity + totalQuantity;
int nProductTotal = int(productTotal * 100);
productTotal = ((float)nProductTotal)/100;
int nTotal = int(total * 100);
total = ((float)nTotal)/100;
cout << productName << " - $" << productTotal << endl;
cout << "Would you like to enter another another product? (Y/N) ";
cin >> YorN;
}
cout << "You have entered " << totalQuantity << " products. Your total amount owed is $" << total << ".\n";
return 0;
}
To show the number of different products you can count them with
...
int totalQuantity(0);
while(YorN == 'Y' || YorN == 'y') {
++totalQuantity;
...
// remove totalQuantity = productQuantity + totalQuantity;
...
}
cout << "You have entered " << totalQuantity << " products. Your total amount owed is $" << total << ".\n";
...
totalQuantity should be of type int and not float as you can't buy 2.2 different products. To round the values to two decimals you can use
productTotal = std::round(price * productQuantity * tax * 100)/100;
Please avoid c style casts like
(float)nTotal
The c++ way to do this is
static_cast<float>(nTotal);
I don't understand what you mean with .29 should be 29.00 but you can achieve this with
double a = 100 * .29;
or
int a = std::round(100 * .29);
or
cout << std::setprecision(2) << 0.29 * 100 << '\n';
I am not done with my code yet but so far I have a error, all the way in the bottom where I am trying to do my do while statement the first line
cout << "Please enter one of the following: \n"; says expected expression so it is not letting me run the code, help please?
#include <iostream>
using namespace std;
int main() {
int numTickets, options, count = 0;
double total, discount, costTicket = 10, discountPrice = .05;
char member;
cout << ":)\t Welcome to the Regal Entertainment Group Theater\t :)\n"
<< ":)\t ****The greatest movie theater in the world.****\t :)\n\n";
cout << "Please enter one of the following: \n";
cout << "1 - I want tickets to watch the movie!\n"
<< "2 - I'm out.\n";
cin >> options;
cout << "How many tickets will you need to watch your movie tonight? ";
cin >> numTickets;
cout << "Are you a member of our marvelous Regal Crown Club (Y/N)? ";
cin >> member;
if(numTickets <= 0)
cout << "Please enter a number greater than 0.";
else if(numTickets < 4)
costTicket = 10;
else if(numTickets >= 5)
costTicket = 8;
if(member == 'Y' || member == 'y')
{
discount = costTicket * numTickets * discountPrice;
total = numTickets * costTicket - discount;
cout << "Your total for the movie tickets is going to be: ";
cout << "$" << total << endl;
cout << "You saved $" << discount << endl;
cout << "You can pick up your free small popcorn at the stand.\n";
cout << "Thanks for coming to watch your movie at Regal Entertainment Group!\n";
}
else
{
total = numTickets * costTicket;
cout << "Your total for the movie tickets is going to be: ";
cout << "$" << total << endl;
cout << "Thanks for coming to watch your movie at Regal Entertainment Group!\n";
}
system("cls");
do
{
cout << "Please enter one of the following: \n";
cout << "1 - I want tickets to watch the movie!\n";
cout << "2 - I'm out.\n";
cin >> options;
}while(options != 2);
return 0;
}
Need help writing a program for class. Here were the posted instructions:
Step 1: The program should have a FUNCTION that displays a screen that shows which seats are available and which are taken. Seats that are taken should be represented by a # symbol and seats that are available should be represented by a * symbol. The first thing your program should do is initialize all of the seats to available (*) and display the seating chart. (HINT: The seating chart should be a two dimensional array.)
Step 2: Each row in the auditorium has a different ticket price. So tickets in row 0 may be 5.00 each and tickets in row 1 may be 10.00 each. Your program should have a FUNCTION that reads the ticket price of each row from an input file called prices.dat. The ticket price for each row should be stored in a one dimensional array.
Step 3: Your program should have variables tracking the total number of tickets sold and the total revenue for all tickets sold.
Step 4:
Your program should allow the user to sell tickets one at a time. The user should be able to sell as many tickets as they would like (you need a loop for this). Do this with some sort of prompt or menu asking the user if they would like to sell another ticket. Don’t forget to validate input data if you need to.
To allow the user to sell a ticket your program should have the user enter a row number and a seat number for the ticket they would like to sell. The program should do four things with this information:
It should check to see if the seat is available. If the seat is taken the program should not allow the user to sell the ticket. If this happens, print a message to the user saying the ticket is not available and prompt the user to see if they would like to sell another ticket.
If the seat is available the program should update the seating chart by putting a taken symbol (#) in that seat’s position in the chart.
The program should then look up the row price for the seat sold. Your program should have a variable tracking the total revenue, the price of the seat sold should be added to this total after each sale.
Your program should have a variable tracking the total tickets sold. The next thing your program should do when selling a ticket is update the total tickets sold.
Step 5: Once the user is finished selling tickets print out an updated seating chart followed by the total tickets sold and the total revenue generate from those tickets.
NOTE: You are required to use two arrays in this program, one for the seating chart and one to store the prices for each row. You are also required to use two functions: one to display the seating chart and one to read in the price per row data and store it in the array with the prices for each row in it. You may use other functions if you want to but they are not required.
Note: The test data file for this run: prices.txt
10
10
10
9
9
9
8
8
8
7
7
7
6
6
6
I am stuck on step two where it says:
"Your program should have a FUNCTION that reads the ticket price of each row from an input file called prices.dat. The ticket price for each row should be stored in a one dimensional array."
I have no idea on how to create input files or check them for that matter.
Here is my code so far. I stopped in my case '1' after checking for duplicate seats. How would I then match the row with the price I want to charge from a data file?
#include <iostream>
#include <iomanip>
#include <string>
#include <istream>
#include <fstream>
using namespace std;
const int numberOfRow = 15;
const int numberOfCol = 20;
void print(char matrix[][20], int numberOfRow, int numberOfCol);
int main()
{
char matrix[numberOfRow][numberOfCol], seat[numberOfRow][numberOfCol];
char option;
int i, j;
int row,col;
int ticketsold = 0;
bool another =true;
for(i = 0; i < numberOfRow; i++)
for(j = 0; j < numberOfCol; j++)
matrix[i][j] = '*';
while(another)
{
print( matrix, numberOfRow, numberOfCol );
cout << "\nMenu:\n";
cout << "1) Buy ticket\n";
cout << "2) Total sell and exit\n\n";
cout << "Enter your choice : ";
cin >> option;
cout << endl << endl;
switch (option)
{
case '1' :
{
cout << "Enter row: ";
cin >> row;
cout << "\nEnter seat: ";
cin >> col;
if( matrix[row][col] == '*')
{
matrix[row][col] = '#';
ticketsold++;
}
else
{
cout << "Invalid seat choice";
}
//total revenue
}
/*case '2' :
{
another=false;
}
default :
cout << "Invalid choice";*/
}
}
system("pause");
}
void print(char matrix[][20], int numberOfRow, int numberOfCol)
{
int row, col, i, j;
cout << "* Seats available\n";
cout << "# Reserved Seats\n";
cout << "Seats: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19" << endl;
for(i = 0; i < numberOfRow; i++)
{
cout << "Row" << setw(3) << i;
for(j=0; numberOfCol > j; j++)
cout << setw(3) << matrix[i][j];
cout << endl;
}
}
The below program is almost similar to your requirement, except reading input from file.
This program will read input from console (user has to key-in price for each row.)
Again, this is not exactly how you want, but I hope it will help you. If possible, soon I'll post another program which can read input from file.
#include <iostream>
#include <iomanip>
using namespace std;
int Show_Menu ();
void Show_Chart ();
const char FULL = '*';
const char EMPTY = '#';
const int rows = 15;
const int columns = 30;
char map [rows][columns];
double price;
int total = 0;
int seat = 450;
int seat2 = 0;
int Quit = 1;
int main ()
{
const int Num_Rows = 15;
int price [Num_Rows];
int row2, column2, cost;
int answer;
cout << "\t*********************************************************" << endl;
cout << "\t* *" << endl;
cout << "\t* Welcome to our small town Theater *" << endl;
cout << "\t* *" << endl;
cout << "\t*********************************************************" << endl;
cout << endl << endl;
for (int count = 0; count < rows; count++)
{
cout << "Please enter the price for row " << (count + 1) << ": ";
cin >> price [count];
}
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
map [i][j] = EMPTY;
}
int choice;
do
{
choice = Show_Menu();
switch (choice)
{
case 1:
cout << "View Seat Prices\n\n";
for (int count = 0; count < rows; count++)
{
cout << "The price for row " << (count + 1) << ": ";
cout << price [count] << endl;
}
break;
case 2:
cout << "Purchase a Ticket\n\n";
do
{
cout << "Please select the row you would like to sit in: ";
cin >> row2;
cout << "Please select the seat you would like to sit in: ";
cin >> column2;
if (map [row2] [column2] == '*')
{
cout << "Sorry that seat is sold-out, Please select a new seat.";
cout << endl;
}
else
{
cost = price [row2] + 0;
total = total + cost;
cout << "That ticket costs: " << cost << endl;
cout << "Confirm Purchase? Enter (1 = YES / 2 = NO)";
cin >> answer;
seat = seat - answer;
seat2 += answer;
if (answer == 1)
{
cout << "Your ticket purchase has been confirmed." << endl;
map [row2][column2] = FULL;
}
else if (answer == 2)
{
cout << "Would you like to look at another seat? (1 = YES / 2 = NO)";
cout << endl;
cin >> Quit;
}
cout << "Would you like to look at another seat?(1 = YES / 2 = NO)";
cin >> Quit;
}
}
while (Quit == 1);
break;
case 3:
cout << "View Available Seats\n\n";
Show_Chart ();
break;
case 4:
cout << "Total ticket sales: "<<total<<".\n\n";
break;
case 5:
cout << "quit\n";
break;
default : cout << "Error input\n";
}
} while (choice != 5);
return 0;
}
//********************************************************************************
//********************************************************************************
//** **
//** Define Functions. **
//** **
//********************************************************************************
//********************************************************************************
int Show_Menu()
{
int MenuChoice;
cout << endl << endl;
cout << " \tMAIN MENU\n";
cout << " 1. View Seat Prices.\n";
cout << " 2. Purchase a Ticket.\n";
cout << " 3. View Available Seats.\n";
cout << " 4. View Ticket Sales.\n";
cout << " 5. Quit the program.\n";
cout << "_____________________\n\n";
cout << "Please enter your choice: ";
cin >> MenuChoice;
cout << endl << endl;
return MenuChoice;
}
void Show_Chart ()
{
cout << "\tSeats" << endl;
cout << " 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30\n";
for (int count = 0; count < 15; count++)
{
cout << endl << "Row " << (count + 1);
for (int count2 = 0; count2 < 30; count2++)
{
cout << " " << map [count] [count2];
}
}
cout << endl;
}
In my program I am trying to call the void function from Main but I can't figure out the correct way.
Main is at the very bottom and void GetTicketType(char &Choice) is the function I need to call to cout the ticket type.
//---------------------------------------------------------------------------
// Purpose: This program simulates a ticket office for sporting events
// Author: TBA
// Date: TBA
//---------------------------------------------------------------------------
#include <iostream>
#include <iomanip>
using namespace std;
const char CASH = 'C';
const char CREDIT = 'D';
const char NOSEBLEED = 'N';
const char BOX_SEAT = 'B';
const char FIFTY_YARD_LINE = 'F';
const char STUDENT_SECTION = 'S';
const float NOSEBLEED_PRICE = 43.42;
const float BOX_SEAT_PRICE = 353.85;
const float FIFTY_YARD_LINE_PRICE = 94.05;
const float STUDENT_SECTION_PRICE = 19.99;
//---------------------------------------------------------------
// Function: ConfirmChoice
// Purpose: Confirms the users ticket purchase before processing payment
// Parameters: TicketType - The type of ticket selected
// Returns: true if the user confirms the selection, false otherwise
//--------------------------------------------------------------
bool ConfirmChoice(const char TicketType)
{
char Choice;
bool Confirmed;
// Print out their selection
cout << "\nYou have chosen to purchase ";
cout << fixed << setprecision(2);
switch (TicketType)
{
case NOSEBLEED:
cout << "Nosebleed ticket(s) at a price of $";
cout << NOSEBLEED_PRICE << ".\n";
break;
case BOX_SEAT:
cout << "Box Seat ticket(s) at a price of $";
cout << BOX_SEAT_PRICE << ".\n";
break;
case FIFTY_YARD_LINE:
cout << "Ticket(s) on the 50 yard line at a price of $";
cout << FIFTY_YARD_LINE_PRICE << ".\n";
break;
case STUDENT_SECTION:
cout << "Ticket(s) in the Student Section at a price of $";
cout << STUDENT_SECTION_PRICE << ".\n";
break;
}
// Confirm the selection
cout << "Do you wish to confirm your purchase? Enter Y or N: ";
cin >> Choice;
Choice = toupper(Choice);
while (Choice != 'Y' && Choice != 'N')
{
cout << "Invalid selection. Please enter either Y or N: ";
cin >> Choice;
Choice = toupper(Choice);
}
Confirmed = (Choice == 'Y');
// Check confirmation
if (Confirmed)
cout << "You have confirmed your choice.\n" << endl;
else
cout << "You not confirmed your choice.\n" << endl;
return (Confirmed);
}
//-------------------------------------------
// Function: CalculateChange
// Purpose: To output the change due
// Parameters: ChangeDue - The amount of change needed
// Returns: Nothing
//-------------------------------------------
void CalculateChange(const float ChangeDue)
{
int Change = 0;
int Dollars = 0;
int Quarters = 0;
int Dimes = 0;
int Nickels = 0;
int Pennies = 0;
// Compute change
Change = ChangeDue * 100;
Dollars = Change / 100;
Change = Change % 100;
Quarters = Change / 25;
Change = Change % 25;
Dimes = Change / 10;
Change = Change % 10;
Nickels = Change / 5;
Pennies = Change % 5;
// Print out change
cout << "Your change is \n\t";
cout << Dollars << " Dollars\n\t";
cout << Quarters << " Quarters\n\t";
cout << Dimes << " Dimes\n\t";
cout << Nickels << " Nickels\n\t";
cout << Pennies << " Pennies\n";
}
//---------------------------------------------------------------------------
// Function: CalculateCost
// Purpose: Calculate the cost of the ticket purchase(s) (num_tickets * price_per_ticket)
// Parameters: PricePerTicket - Ticket price based on the type of ticket
// Returns: The cost of purchasing the chosen number of tickets
//---------------------------------------------------------------------------
float CalculateCost(const float PricePerTicket)
{
int TicketCount;
float Cost;
cout << "How many tickets would you like? Please enter a positive integer value: ";
cin >> TicketCount;
while (TicketCount < 0)
{
cout << "Invalid entry. Please re-enter: ";
cin >> TicketCount;
}
Cost = PricePerTicket * TicketCount;
cout << "Your bill is: $" << fixed << setprecision(2) << Cost << endl;
return Cost;
}
//---------------------------------------------------------------------------
// Function: GetPaymentType
// Purpose: Ask the user how they want to pay, cash or credit
// Parameters: None
// Returns: Value is CREDIT or CASH (global character constants)
//---------------------------------------------------------------------------
char GetPaymentType()
{
char Choice;
// Print the main menu describing the ticket payment types
cout << "+-------------------------------------------------------+\n";
cout << "+ Welcome to our Ticket Office +\n";
cout << "+-------------------------------------------------------+\n";
cout << endl << endl;
// Cash or credit card (in upper case)
cout << "How would you like to pay?\n";
cout << "Enter C for cash or D for credit card: ";
cin >> Choice;
Choice = toupper(Choice);
while (Choice != CASH && Choice != CREDIT)
{
cout << "Invalid choice. Please enter C for cash or D for credit card: ";
cin >> Choice;
Choice = toupper(Choice);
}
return Choice;
}
//---------------------------------------------------------------------------
// Function: GetTicketType
// Purpose: Get the customer's choice between 4 types of tickets
// Parameters: Choice - Set to the user's choice
// Returns: Nothing
//---------------------------------------------------------------------------
void GetTicketType(char &Choice)
{
// Ask the customer what type of ticket s/he prefers to buy
cout << "\nWhat type of ticket would you like?\n";
cout << "\t" << NOSEBLEED << " for Nosebleed Section, Price = $";
cout << NOSEBLEED_PRICE << endl;
cout << "\t" << BOX_SEAT << " for Box Seats, Price = $";
cout << BOX_SEAT_PRICE << endl;
cout << "\t" << FIFTY_YARD_LINE << " for Seats on the Fifty Yard Line, Price = $";
cout << FIFTY_YARD_LINE_PRICE << endl;
cout << "\t" << STUDENT_SECTION << " for Student Section, Price = $";
cout << STUDENT_SECTION_PRICE << endl;
// Get ticket choice (in upper case)
cout << "Enter choice: ";
cin >> Choice;
Choice = toupper(Choice);
while (Choice != NOSEBLEED && Choice != BOX_SEAT &&
Choice != FIFTY_YARD_LINE && Choice != STUDENT_SECTION)
{
cout << "Invalid choice. Please re-enter: ";
cin >> Choice;
Choice = toupper(Choice);
}
}
//---------------------------------------------------------------------------
// Function: PayWithCash
// Purpose: Handles payment by cash. Asks the user for the money until
// they enter enough, then updates the ChangeDue parameter
// Parameters: Cost - The amount due for the purchase
// ChangeDue - The amount of change due to customer
// Returns: Nothing
//---------------------------------------------------------------------------
void PayWithCash(const float Cost, float &ChangeDue)
{
float CashOffered;
// Pay in cash
cout << "Please enter enough cash. Your bill is $" << Cost << ": $ ";
cin >> CashOffered;
// Check sufficiency
while (CashOffered < Cost)
{
cout << "That is not enough to pay for your purchase!\n"
<< " Please enter at least $" << Cost << ": ";
cin >> CashOffered;
}
// Calculate change
ChangeDue = CashOffered - Cost;
}
//---------------------------------------------------------------------------
// Function: PayWithCredit
// Purpose: Handles payment by credit. Basically, just prints a statement
// telling them that their card will be charged.
// Parameters: const float Cost - the amount due for the purchase
// Returns: Nothing
//---------------------------------------------------------------------------
void PayWithCredit(const float Cost)
{
cout << "Your credit card will be billed for $" << Cost << ".\n";
}
//---------------------------------------------------------------------------
// Function: main
// Purpose: This is the main program that calls functions above.
// Parameters: None
// Returns: Nothing
//---------------------------------------------------------------------------
int main()
{
// Declarations
char TChoice ; // Ticket type: Nosebleed, box seats etc..
TChoice << GetTicketType( &TChoice);
char PChoice = GetPaymentType() ; // Payment choice: cash or credit card
bool Confirmed; // Did the user confirm the selection
float Cost; // The cost of the ticket puchased
float ChangeDue; // The amount of change owed (for cash purchases)
// Print your name and UAID
// Get the choice of payment type
// Get the choice of ticket type
GetTicketType(TChoice );
{
cout << "You have chosen the " << TChoice << "tickets. " <<".\n";
}
// Confirm the selection
// If they confirm the purchase
// Call functions to figure out the price of ticket purchase(s)
// Be sure to use the named constants
// Handle the payment
// Say goodbye
// Else
// Cancel the purchase
return 0;
}
Change
TChoice << GetTicketType( &TChoice);
To Simple
GetTicketType( &TChoice);
Since TChoice << GetTicketType( &TChoice); is doing bitwise left shift operation it will expect an integer type after <<.Your function is returning nothing(void) and thus causes an error.
It looks like you're getting an error on this line:
TChoice << GetTicketType( &TChoice);
You're calling GetTicketType and expecting to use the result. Is that really what you want to do, since it's a void function?