Code:
#include <iostream>
#include <string>
#include <iomanip>
#include <ctime>
#include <algorithm>
#include <stdio.h>
#include <time.h>
using namespace std;
char get_ticket_type();
double find_ticket_price(char ticket_type,int num_tickets, double junior_tick, double adult_tick, double sales);
void disp_ticket_type(char ticket_type);
int main()
{
time_t t;
time(&t); //get current date and time
struct tm *pt = localtime(&t); //convert time_t to a structure
//Declare Variables
int Max_Seat_Count = 40, tot_num_tickets = 0, extra_seats = 0,toddler = 0, a_num_dis_ct = 0, disc_tick_sold = 0;
int adult_tick_sold = 0, jun_tick_sold = 0, num_dis_ct = 0, num_tickets = 0;
double adult_sales = 0.0, a_total_discount_sales = 0.0, j_total_discount_sales = 0.0;
double junior_tick =7.50, adult_tick = 11.50, grand_total = 0.0, discount = 0.25, jun_sales = 0.0,sales = 0.0, tot_ad_sales = 0.0;
double a_discount_sales = 0.0, j_discount_sales = 0.0, tot_jun_sales = 0.0;
string name = " ";
char ticket_type = ' ', dis_count = ' ';
//Intro to Program
cout <<setw(50) << "Welcome to Seaworld of Summerville Ticketmaster." <<endl << endl;
cout << "We will be selling alot of tickets for the up coming shows." <<endl;
cout <<"So lets go over a number of things you should know." << endl;
cout << "May I please have your Name? ";
cin >> name;
cout << endl << endl;
cout << "Well, " << name <<" Let's get started on the basics of the program. It" << endl;
cout <<"will be real simple to understand. All you need to do " <<name <<" is enter how many" << endl;
cout << "tickets the customer wants of a certian kind of ticket. The ticket names are" << endl << endl;
cout << " 'T' for Toddler ages 5 and under are free" << endl;
cout <<" 'J ' for Juniors age 6 to 16 are $7.50" << endl;
cout << " 'A' for Adults 16 and over are $11.50" <<endl << endl << endl;
cout <<"So all you have to do is enter the number of tickest per catagory and" <<endl;
cout << "the computer will do the rest of the work for you. You are only aloud"<< endl;
cout << "to sell 10 tickets per type of seat, the computer is defaulted to 10" << endl;
cout << "so it will not let you sell anymore than 10 per type of seat." << endl << endl <<endl;
cout << "If you need to shut down the system all you have to do is" << endl;
cout << "type 'Q' and your out of the program.." <<endl << endl;
cout <<"The program will also end when you sell all the seats availble for the show." << endl << endl;
cout << "So Good Luck and have a Great Day!!" << endl;
// End of program intro
system("pause");
system("cls");
ticket_type = get_ticket_type();
// CENTRAL WHILE LOOP
while (ticket_type != 'Q')
{
cout <<"Enter how many tickets do you wish to purchase today? : ";
cin >>num_tickets;
cout <<endl;
//BEGINNING MAX TICKET
if (num_tickets >10)
{
cout <<"ERROR MAXIMUM AMOUT OF TICKETS YOU ARE ALLOWED TO SELL IS '10' ";
num_tickets = 10;
}//END OF MAX TICKET
sales = find_ticket_price(ticket_type, num_tickets, junior_tick, adult_tick, sales);
// END WHILE != Q
if (ticket_type == 'T')
toddler += num_tickets;
else if (ticket_type == 'J')
{
jun_tick_sold += num_tickets;
jun_sales += sales;
}
else
{
adult_tick_sold += num_tickets ;
adult_sales += sales;
}
ticket_type = get_ticket_type();
/*dis_count = apply_discount(ticket_type, dis_count, discount_sales, discount, sales);*/
}
if (dis_count == 'Y' && ticket_type =='J')
{
num_dis_ct += num_tickets ;
j_total_discount_sales += j_discount_sales;
}
else if (dis_count == 'Y' && ticket_type == 'A')
{
a_num_dis_ct += num_tickets;
a_total_discount_sales += a_discount_sales;
}
return 0;
}
// GET TICKET TYPE
char get_ticket_type()
{
int num_tickets = 0;
char ticket_type = ' ';
cout << "What type of Ticket Do you wish To purchase today? Toddler, Junior, Adult" <<endl;
cout << setw(10) << "Enter 'T', 'J', or 'A' ticket type or 'Q' to quit: ";
cin >> ticket_type;
ticket_type = toupper(ticket_type);
// WHILE CHECKING TICKET TYPE VALIDITY
while (ticket_type != 'T' &&
ticket_type != 'J' &&
ticket_type != 'A' &&
ticket_type != 'Q')
{
cout <<"*****ERROR Wrong ticket Type Try Again*****" <<endl;
cout << "Enter 'T', 'J', or 'A' ticket type or 'Q' to quit Enter ticket type -->";
cin >> ticket_type;
ticket_type = toupper(ticket_type);
cout << endl;
}//END WHILE CHECKING ERROR
return ticket_type;
}// END GET TICKET TYPE
double find_ticket_price(char ticket_type,int num_tickets, double junior_tick, double adult_tick, double sales)
{
/*int num_tickets = 0;
double junior_tick = 0.0, adult_tick = 0.0, sales = 0.0;*/
char dis_count = ' ';
double discount_sales = 0.0, discount = 0.25;
if (ticket_type == 'T')
{
disp_ticket_type(ticket_type);
cout << " Amount is Free IM IN THE LOOP" << endl;
}
else if (ticket_type == 'J')
{
cout << fixed <<setprecision(2);
sales = num_tickets* junior_tick;
disp_ticket_type(ticket_type);
cout << " Total is:IM IN THE LOOP $" <<sales << endl;
cout << " Do you have any discount? ";
cin >> dis_count;
/*if (dis_count == 'Y')
apply_discount(find_ticket_price, ticket_type, dis_count, discount_sales, discount, sales);*/
}
else
{
sales = num_tickets * adult_tick;
disp_ticket_type(ticket_type);
cout << " Total is:IM IN THE LOOP $" <<sales << endl;
cout << " Do you have any discount? ";
cin >> dis_count;
/*if (dis_count == 'Y')
apply_discount(find_ticket_price,ticket_type, dis_count, discount_sales, discount, sales);*/
}
return (sales);
}
void disp_ticket_type(char ticket_type)
{
ticket_type = toupper(ticket_type);
if (ticket_type =='T')
cout <<"Toddler";
else if (ticket_type =='J')
cout << "Junior";
else
cout<<"Adult";
}//End of Display ticket type