Programming Challenge Chapter 3 – Q #5 Box Office – Tony Gaddis – Starting Out With C++
Problem: -
Solution: -
#include <iostream>
#include<string>
using namespace std;
int main()
{
const float ADULT = 6,
CHILD = 3,
PROFIT_PERCENTAGE = 0.2;
string name;
float ticket1, ticket2;
float boxOffice = 0.0, netProfit = 0.0, distributer_ammount = 0.0;
float adult, child;
cout << "Enter Movie Name:
";
getline(cin, name);
cout << "How many Child ticket
Sale: ";
cin >> ticket1;
cout << "How many Adult ticket
Sale: ";
cin >> ticket2;
child = ticket1 * CHILD;
adult = ticket2 * ADULT;
boxOffice = child + adult;
netProfit = boxOffice * PROFIT_PERCENTAGE;
distributer_ammount = boxOffice - netProfit;
cout << "\nMovie Name: " << name << endl;
cout << "Adult Ticket
Sold: " << ticket2 << endl;
cout << "Child Ticket
Sold: " << ticket1 << endl;
cout << "Box Office: $" << boxOffice << endl;
cout << "Net Profit: $" << netProfit << endl;
cout << "Ammount Paid to
Distributer: $" << distributer_ammount << endl;
return 0;
}
This is the solution of this question
OUTPUT OF THIS QUESTION
Input is highlighted with yellow color.
Explanation of this Solution
- Use string header file for string variables.
- Declare three float constant and initialize given values.
- Declare a string variable for movie name.
- Declare two float variables for tickets input.
- Declare three float variables for calculation.
- Declare another two float variables for calculation.
- Take input of movie name from the user by using cin.
- Take input of tickets from the user by using cin.
- Calculate child and adult ticket prices.
- Calculate profits and distributer amount.
- In last, display output on the screen.
- Return 0 to the main function.
Also, I attach CPP file of this problem. You can download this file
0 Comments