fork download
  1. // Torrez, Elaine CS1A Chapter 3 P. 143, #2
  2.  
  3. /******************************************************************************************
  4.  *
  5.  * CALCULATE STADIUM SEATING INCOME
  6.  *
  7.  * --------------------------------------------------------------------------------
  8.  * This program asks the user to enter the number of Class A, Class B, and Class C
  9.  * tickets sold for a softball game. It then calculates and displays the income
  10.  * generated from each class of seats as well as the total income from all ticket sales.
  11.  * --------------------------------------------------------------------------------
  12.  *
  13.  * INPUT
  14.  * ticketsA : Number of Class A tickets sold
  15.  * ticketsB : Number of Class B tickets sold
  16.  * ticketsC : Number of Class C tickets sold
  17.  *
  18.  * OUTPUT
  19.  * incomeA : Income from Class A ticket sales
  20.  * incomeB : Income from Class B ticket sales
  21.  * incomeC : Income from Class C ticket sales
  22.  * totalIncome : Total income from all ticket sales
  23.  *
  24.  *******************************************************************************************/
  25.  
  26. #include <iostream>
  27. #include <iomanip> // Included for fixed and setprecision
  28. using namespace std;
  29.  
  30. int main ()
  31. {
  32. // Constants
  33. const double PRICE_A = 15.00; // Price of Class A ticket
  34. const double PRICE_B = 12.00; // Price of Class B ticket
  35. const double PRICE_C = 9.00; // Price of Class C ticket
  36.  
  37. // Variables (ABC order)
  38. double incomeA; // OUTPUT Income from Class A
  39. double incomeB; // OUTPUT Income from Class B
  40. double incomeC; // OUTPUT Income from Class C
  41. double totalIncome; // OUTPUT Total income
  42. int ticketsA; // INPUT Number of Class A tickets sold
  43. int ticketsB; // INPUT Number of Class B tickets sold
  44. int ticketsC; // INPUT Number of Class C tickets sold
  45.  
  46. // Get input
  47. cout << "Enter the number of Class A tickets sold: ";
  48. cin >> ticketsA;
  49.  
  50. cout << "Enter the number of Class B tickets sold: ";
  51. cin >> ticketsB;
  52.  
  53. cout << "Enter the number of Class C tickets sold: ";
  54. cin >> ticketsC;
  55.  
  56. // Calculate income
  57. incomeA = ticketsA * PRICE_A;
  58. incomeB = ticketsB * PRICE_B;
  59. incomeC = ticketsC * PRICE_C;
  60. totalIncome = incomeA + incomeB + incomeC;
  61.  
  62. // Display results
  63. cout << fixed << setprecision(2);
  64. cout << "\nIncome from Class A tickets: $" << incomeA << endl;
  65. cout << "Income from Class B tickets: $" << incomeB << endl;
  66. cout << "Income from Class C tickets: $" << incomeC << endl;
  67. cout << "---------------------------------" << endl;
  68. cout << "Total Income from ticket sales: $" << totalIncome << endl;
  69.  
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0s 5320KB
stdin
50
75
100
stdout
Enter the number of Class A tickets sold: Enter the number of Class B tickets sold: Enter the number of Class C tickets sold: 
Income from Class A tickets: $750.00
Income from Class B tickets: $900.00
Income from Class C tickets: $900.00
---------------------------------
Total Income from ticket sales: $2550.00