fork download
  1. /*******************************************************************************
  2.  * calculate customer's monthly bill
  3. *_______________________________________________________________________________
  4. * calculates bill based on subscription and hours
  5. *_______________________________________________________________________________
  6. *INPUT
  7. * chosen package
  8. * hours of use
  9. *OUTPUT
  10. * cost of bill
  11. *******************************************************************************/
  12. #include <iostream>
  13. #include <iomanip>
  14. using namespace std;
  15.  
  16. int main() {
  17. char package;
  18. double hours;
  19. double total;
  20.  
  21. cout << "enter your billing package selection:\n";
  22. cin >> package;
  23. cout << "A) $9.95/mo - 10 hrs included - $2/hr additional\n";
  24. cout << "B) $14.95/mo - 20 hrs included - $1/hr additional\n";
  25. cout << "C) $19.95/mo - unlimited\n";
  26. cout << " \n";
  27.  
  28. //input validation
  29. if (package!= 'A' && package != 'a' && package != 'B' && package != 'b' && package != 'C' && package != 'c'){
  30. cout << "please enter a, b, or c.\n";
  31. } else {
  32. cout << "enter number of hours (0-744)\n";
  33. cin >> hours;
  34. }
  35. if (hours <0 || hours>744) {
  36. cout << "invalid hours, please select hours 0-744.\n";
  37. return 1;
  38. }
  39. if (package == 'A' || package == 'a'){
  40. total = 9.95;
  41. if (hours> 10) {
  42. total+= (hours - 10) * 2.00;
  43. }else if (package == 'B' || package == 'b'){
  44. total =14.95;
  45. } if (hours>20) {
  46. total+=(hours-20)*1.00;
  47. }else if (package == 'C' || 'c') { // package c
  48. total =19.95;
  49. }
  50. cout << fixed<<setprecision(2) << "total: $" << total << endl;
  51. }
  52. return 0;
  53. }
Success #stdin #stdout 0s 5320KB
stdin
A
stdout
enter your billing package selection:
A) $9.95/mo - 10 hrs included - $2/hr additional
B) $14.95/mo - 20 hrs included - $1/hr additional
C) $19.95/mo - unlimited
 
enter number of hours (0-744)
total: $19.95