fork download
  1. //Jacklyn Isordia CSC5 Chapter 4, P. 225, #22
  2. //
  3. /**************************************************************
  4.  *
  5.  * Calculate the charges for long-distance phone calls.
  6.  * ____________________________________________________________
  7.  *
  8.  * This program calculates long-distance phone calls by the
  9.  * length of the phone call by calculating the rate per
  10.  * minute. The charge is calculated as numberOfMinutes * rate.
  11.  * ____________________________________________________________
  12.  * INPUT
  13.  * startingTime : start of the call (HH.MM)
  14.  * numberOfMinutes : number of minutes of the call
  15.  *
  16.  * OUTPUT
  17.  * charges = the total charge for the call in dollars
  18.  *
  19.  **************************************************************/
  20. #include <iostream>
  21. #include <iomanip>
  22. using namespace std;
  23.  
  24. int main() {
  25. double startingTime;
  26. int numberOfMinutes;
  27. double charges;
  28. int hours;
  29. double minutes;
  30.  
  31. cout << fixed << setprecision(2);
  32. cout << "Enter the starting time (HH.MM): ";
  33. cin >> startingTime;
  34. hours = static_cast<int>(startingTime);
  35. minutes = startingTime - static_cast<int>(startingTime);
  36.  
  37. cout << "Enter the number of minutes (59): ";
  38. cin >> numberOfMinutes;
  39.  
  40. while (hours > 23 || minutes > 0.59)
  41. {
  42. cout << "Invalid! Enter time between 00.00 and 23.59: ";
  43. cin >> startingTime;
  44. hours = static_cast<int>(startingTime);
  45. minutes = startingTime - static_cast<int>(startingTime);
  46. }
  47.  
  48. if (hours >= 0 && hours <= 6)
  49. charges = numberOfMinutes * 0.12;
  50. else if (hours >= 7 && hours <= 19)
  51. charges = numberOfMinutes * 0.55;
  52. else
  53. charges = numberOfMinutes * 0.35;
  54.  
  55. cout << "The charge for the call is: $" << charges << endl;
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0.01s 5320KB
stdin
6.59
20
stdout
Enter the starting time (HH.MM): Enter the number of minutes (59): The charge for the call is: $2.40