Programming Challenge Chapter 3 – Q #2 Stadium Seating – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 3 – Q #2 Stadium Seating – Tony Gaddis – Starting Out With C++


Problem: -

There are three seating categories at a stadium. For a softball game, Class A seats cost $15, Class B seats cost $12, and Class C seats cost $9. Write a program that asks how many tickets for each class of seats were sold, then displays the amount of income generated from ticket sales. Format your dollar amount in fixed-point notation, with two decimal places of precision, and be sure the decimal point is always displayed.

Solution: -

#include <iostream>

#include<iomanip>

using namespace std;

int main()

{

      const int CLASS_A = 15,

            CLASS_B = 12,

            CLASS_C = 9;

      float class1, class2, class3;

      float total_sale = 0;

      cout << "How many Tickets Sale Of Claas A: $";

      cin >> class1;

      cout << "How many Tickets Sale Of Claas B: $";

      cin >> class2;

      cout << "How many Tickets Sale Of Claas C: $";

      cin >> class3;

      class1 = class1 * CLASS_A;

      class2 = class2 * CLASS_B;

      class3 = class3 * CLASS_C;

      total_sale = class1 + class2 + class3;

      cout << setprecision(2) << fixed << showpoint;

      cout << "Total Sale is $" << total_sale;

      return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION 

Input is highlighted with yellow color.


Explanation of this Solution


  1. Declare three float constants and initialize the given values.
  2. Declare another three float variables for input.
  3. Take input Class 1 from the user by using cin.
  4. Take input Class 2 from the user by using cin.
  5. Take input Class 3 from the user by using cin.
  6. Calculate class 1, class 2 and class 3. 
  7.  In last, display Total Sale output on the screen.
  8. Return 0 to the main function.

Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File




Thanks!  

Post a Comment

0 Comments