fork download
  1. //Andres Guzman CSC5 Chapter 4, P. 226, #23
  2. //
  3. /**************************************************************
  4. *
  5. * SELECT INTERNET PACKAGE
  6. * ____________________________________________________________
  7. * This program will allow the user to select an pacakge and then calculate how
  8. * much the user needs to pay.
  9. *
  10. * Computation is based on the formula:
  11. * total = hours + (hours - selected package limit) * select package charges
  12. * ____________________________________________________________
  13. * INPUT
  14. * choice = Allows selections for programmer
  15. * hours = Allows programmer to input desired hours
  16. * OUTPUT
  17. * total1, total2, total3 = Calculates the total according to package
  18. **************************************************************/
  19. #include <iostream>
  20. using namespace std;
  21.  
  22. int main ()
  23. {
  24. char choice; //Allows for selection
  25. int hours; //Allows desired hours to be inputted
  26. double total1,total2,total3; //Holds calculation of month total
  27. //
  28. //
  29. double packa = 9.95; //First option with additional 2.00 charges per hour
  30. double packb = 14.95; //Second option with additonal 1.00 charges per hour
  31. double packc = 19.95; //Third option with unlimited hours
  32. //
  33. //
  34. cout << "\tInternet Services Packages\n\n";
  35. cout << "Package A" << endl;;
  36. cout << "Package B" << endl;
  37. cout << "Package C" << endl;
  38. cout << "\nWhich Service Package have you purchased? ";
  39. cin >> choice;
  40.  
  41. if(choice != 'A' && choice != 'B' && choice != 'C')
  42. { cout << "\nInvalid Package Selected. Please select A, B, or C.";}
  43. else
  44. {
  45. switch(choice)
  46. {
  47. case 'A' : cout << "\nHow many hours were used? ";
  48. cin >> hours;
  49. if (hours < 0 || hours > 744)
  50. { cout << "\nInvalid, please enter a number between 0 and 744.";}
  51. else if (hours <= 10)
  52. { cout << "\nMonths Total: " << packa;}
  53. else
  54. { total1 = packa + (hours - 10) * 2.00; //calculates extra hours
  55. cout << "\nMonths Total: " << total1;
  56. }
  57. break;
  58. case 'B' : cout << "\nHow many hours were used? ";
  59. cin >> hours;
  60. if (hours < 0 || hours > 744)
  61. { cout << "Invalid, please enter a number between 0 and 744.";}
  62. else if (hours <= 20)
  63. { cout << "\nMonths Total: " << packb;}
  64. else
  65. { total2 = packb + (hours - 20) * 1.00; //calculates extra hours
  66. cout << "\nMonths Total: " << total2;
  67. }
  68. break;
  69. case 'C' : cout << "\nUnlimited Hours Provided. ";
  70. cout << "\nMonth Total: " << packc;
  71. break;
  72. }
  73. }
  74. }
Success #stdin #stdout 0s 5308KB
stdin
C
stdout
	Internet Services Packages

Package A
Package B
Package C

Which Service Package have you purchased? 
Unlimited Hours Provided. 
Month Total: 19.95