fork download
  1. //Kanoa Holden CS1A Chapter 3, P. 143, #2
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * COMPUTE TOTAL SALES OF TICKETS
  6.  * _____________________________________________________________________________
  7.  * This program computes the total income of tickets sold and which class sold
  8.  * the most amount of tickets
  9.  * _____________________________________________________________________________
  10.  * INPUT
  11.  * classA_Tickets : amount of class A tickets sold
  12.  * classA_price : Price of class A tickets
  13.  * classB_tickets : amount of class B tickets sold
  14.  * classB_price : price of class B tickets sold
  15.  * classC_tickets : amount of class C tickets sold
  16.  * classC_price : price of class C tickets
  17.  *
  18.  * OUTPUT
  19.  * total_income : total income from tickets sold
  20.  *
  21.  ******************************************************************************/
  22. #include <iostream>
  23. #include <iomanip>
  24.  
  25. using namespace std;
  26.  
  27. int main() {
  28. // Declare variables to hold the number of tickets sold for each class
  29. int classA_tickets, classB_tickets, classC_tickets;
  30.  
  31. // Prices of each class of seats
  32. const double classA_price = 15.00;
  33. const double classB_price = 12.00;
  34. const double classC_price = 9.00;
  35.  
  36. // Ask the user for the number of tickets sold for each class
  37. cout << "\nEnter the number of Class A tickets sold: ";
  38. cin >> classA_tickets;
  39.  
  40. cout << "\nEnter the number of Class B tickets sold: ";
  41. cin >> classB_tickets;
  42.  
  43. cout << "\nEnter the number of Class C tickets sold: ";
  44. cin >> classC_tickets;
  45.  
  46. // Calculate the total income generated from ticket sales
  47. double total_income = (classA_tickets * classA_price) +
  48. (classB_tickets * classB_price) +
  49. (classC_tickets * classC_price);
  50.  
  51. // Display the total income
  52. cout << fixed << setprecision(2);
  53. cout << "\nTotal income generated from ticket sales: $" << total_income << endl;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5288KB
stdin
30
25
32
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: 
Total income generated from ticket sales: $1038.00