fork download
  1. //Xinnuo Wang CS1A chapter 4, p.226 #23
  2. //
  3. /*******************************************************************************
  4.  *
  5.  * Caculate bills under different subscription packages
  6.  * _____________________________________________________________________________
  7.  * This program accepts hours and packages to caculate the bills.
  8.  *
  9.  * Computation is based on the formula:
  10.  * Bills = basic bills + extra bills
  11.  * _____________________________________________________________________________
  12.  * INPUT
  13.  * Basic Bills : The basic bills in limited time
  14.  * Extra Bills : The extra bills pay for excessive time
  15.  * Hours : Used hours in a month
  16.  * Choice : The different subscription packages for customers
  17.  * OUTPUT
  18.  * Total bills : The total bills in a month
  19.  *
  20.  ******************************************************************************/
  21. #include <iostream>
  22. using namespace std;
  23.  
  24. int main()
  25. {
  26. float hours; //INPUT - Used hours in a month
  27. float basicBills; //INPUT - The basic bills in limited time
  28. float extraBills; //INPUT - The extra bills pay for excessive time
  29. int choice; //INPUT - The different subscription packages for customers
  30. float totalBills; //OUTPUT - The total bills in a month
  31. cout <<"===== MANU ====="<<endl;
  32. cout <<"1. Package A"<<endl;
  33. cout <<"2. Package B"<<endl;
  34. cout <<"3. Package C"<<endl;
  35. //
  36. //Data Input
  37. cout<<"Enter choice"<<endl;
  38. cin>>choice;
  39. cout <<"Enter hours"<< endl;
  40. cin>>hours;
  41. //
  42. //Check validation
  43. if(hours>744)
  44. {
  45. cout<<"Invalid time"<< endl;
  46. return 0;
  47. }
  48. //
  49. //Output
  50. switch(choice)
  51. {
  52. case 1:
  53. if(hours<=10)
  54. {
  55. totalBills = 9.95;
  56. cout << "The total bills are: $" <<totalBills <<endl;
  57. }
  58. else
  59. {
  60. totalBills = 9.95 +(hours - 10) *2;
  61. cout << "The total bills are: $" <<totalBills <<endl;break;
  62. }
  63. case 2:
  64. if(hours<=20)
  65. {
  66. totalBills = 14.95;
  67. cout << "The total bills are: $" <<totalBills <<endl;
  68. }
  69. else
  70. {
  71. totalBills = 14.95 +(hours - 20) *1;
  72. cout << "The total bills are: $" <<totalBills <<endl;break;
  73. }
  74. case 3:
  75. {
  76. totalBills = 19.95;
  77. cout << "The total bills are: $" <<totalBills <<endl;break;
  78. }
  79. default:
  80. cout<<"Invalid choice"<< endl;
  81. }
  82. return 0;
  83. }
Success #stdin #stdout 0.01s 5288KB
stdin
2 56
stdout
===== MANU =====
1. Package A
2. Package B
3. Package C
Enter choice
Enter hours
The total bills are: $50.95