Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are to write a program that allows a user purchase tickets to a Broadway musical. The program asks the user how much money they

You are to write a program that allows a user purchase tickets to a Broadway musical. The
program asks the user how much money they have to spend on tickets and then asks them how
many tickets they would like to purchase. The program must implement the following function
that is called once the user has entered all the information:
/*****************************************************************
*
* Function: PurchaseTickets
*
* Parameters:
*
* pRemainingCash - points to a variable containing the
* amount of cash the user has
*
* adultTickets - specifies the number of adult tickets
* the user wants to purchase.
*
* childTickets - specifies the number of child tickets
* the user wants to purchase.
*
** Description:
* The function will determine if the user has enough
* money to purchase the specified number of tickets.
* If they do, then the function deducts the proper
* funds from their remaining cash and returns
* the total number of tickets purchased. If they do not
* the function returns 0.
*
******************************************************************/
int PurchaseTickets(double *pRemainingCash, int adultTickets,
int childTickets);
You must also use the following two constants to represent the ticket prices:
#define ADULT_TICKET_PRICE 69.00
#define CHILD_TICKET_PRICE 35.00
The program must prompt the user for the following information and in the following order:
Amount of cash they have
Number of child tickets to purchase
Number of adult tickets to purchase
If the user has enough money to purchase the requested tickets, display the number of tickets
they purchased and the remaining cash they have after the purchase. If the user does not have
enough money to purchase the tickets, tell them and exit the program.
Here are two sample interactions:
Sample 1:
How much money do you have to purchase tickets?
300.00
How many child tickets would you like to purchase?
2
How many adult tickets would you like to purchase?
3
You have purchased 5 tickets, and you have $23.00 remaining
Sample 2:
How much money do you have to purchase tickets?
100.00
How many child tickets would you like to purchase?
2
How many adult tickets would you like to purchase?
4
You do not have enough money to purchase the tickets
Here is what I have so far:
#include
#define ADULT_TICKET_PRICE 69.00
#define CHILD_TICKET_PRICE 35.00
int PurchaseTickets(double *pRemainingCash, int adultTickets, int childTickets);
int main(void)
{
double cash;
int childTickets;
int adultTickets;
//printf to ask for the amount of cash
printf("How much money do you have to purchase tickets?:
");
//scanf and error checking
scanf("%d", cash);
//ask for number of child tickets
printf("How many child tickets would you like to purchase?:
");
// scanf and error checking
scanf("%d", childTickets);
//ask for number of adult tickets
printf("How many adult tickets would you like to purchase?:
");
// scanf and error checking
scanf("%d", adultTickets);
if (PurchaseTickets(&cash, adultTickets, childTickets)>0)
{
printf("You have purchased %d tickets, and you have $%3.2f remaining.", adultTickets + childTickets, cash);
}
else
{
printf("You did not purchase any tickets.
");
}
return 0;
}
int PurchaseTickets(double *pRemainingCash, int adultTickets, int childTickets)
{
int numTicketsPurchased =0;
return numTicketsPurchased; // if user does not have enough money for the tickets
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

b. Will new members be welcomed?

Answered: 1 week ago

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago