Chapter 3 – #7: Box Office – Tony Gaddis – Starting Out With C++

>_ Problem

A movie theater only keeps a percentage of the revenue earned from ticket sales. The remainder goes to the movie distributor. Write a program that calculates a theater’s gross and net box office profit for a night. The program should ask for the name of the movie, and how many adult and child tickets were sold. (The price of an adult ticket is $10.00 and a child’s ticket is $6.00.) It should display a report similar to

Movie Name:                                            “Wheels of Fury”
Adult Tickets Sold:                                             382
Child Tickets Sold:                                              127
Gross Box Office Profit:                      $ 4582.00
Net Box Office Profit:                           $     916.40
Amount Paid to Distributor:              $ 3665.60

NOTE: Assume the theater keeps 20 percent of the gross box office profit.

>_ Solution

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
    // Constant variables
    const float ADULT_PRICE = 10,
                CHILD_PRICE = 6,
                PROFIT = .20;

    string movie_name;

    int adult_tkt,
        child_tkt;

    float total,
          theater_per;

    // Ask for movie name
    cout << "\nWhat was the name of the movie? ";
    getline(cin, movie_name);

    // Ask for number of adult and child tickets
    cout << "\nHow many adult tickets? ";
    cin >> adult_tkt;
    cout << "How many child tickets? ";
    cin >> child_tkt;

    // Calculate gross and net profit
    total = (adult_tkt * ADULT_PRICE) + (child_tkt * CHILD_PRICE);
    theater_per = total * PROFIT;

    // Display report
    cout << setprecision(2) << fixed;
    cout << "\nMovie Name: \"";
    cout << movie_name << '\"' <<endl;
    cout << "Adult tickets sold:      " << setw(10);
    cout << adult_tkt;
    cout << "\nChild tickets sold:      " << setw(10);
    cout << child_tkt;
    cout << "\nTotal cost:              " << setw(10);
    cout << total;
    cout << "\nGross Box Office Profit: " << setw(10);
    cout << theater_per << '\n' <<endl;

    // Terminate Program
    return 0;
}

>_Get The Book!

>_ Video Walk Through

This video includes a step by step process of how I solve programming challenge #7.

>_That’s it!

Thank you for taking interest in what I do! I hope it was helpful for you as much as it helped me along my journey in learning to code!

>_ Also Check Out:

Category: Starting Out With C++ | Chapter 3 | Programming Challenge Solutions

Leave a Reply