//Jacklyn Isordia CSC5 Chapter 4, P. 225, #22
//
/**************************************************************
*
* Calculate the charges for long-distance phone calls.
* ____________________________________________________________
*
* This program calculates long-distance phone calls by the
* length of the phone call by calculating the rate per
* minute. The charge is calculated as numberOfMinutes * rate.
* ____________________________________________________________
* INPUT
* startingTime : start of the call (HH.MM)
* numberOfMinutes : number of minutes of the call
*
* OUTPUT
* charges = the total charge for the call in dollars
*
**************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double startingTime;
int numberOfMinutes;
double charges;
int hours;
double minutes;
cout << fixed << setprecision(2);
cout << "Enter the starting time (HH.MM): ";
cin >> startingTime;
hours = static_cast<int>(startingTime);
minutes = startingTime - static_cast<int>(startingTime);
cout << "Enter the number of minutes (59): ";
cin >> numberOfMinutes;
while (hours > 23 || minutes > 0.59)
{
cout << "Invalid! Enter time between 00.00 and 23.59: ";
cin >> startingTime;
hours = static_cast<int>(startingTime);
minutes = startingTime - static_cast<int>(startingTime);
}
if (hours >= 0 && hours <= 6)
charges = numberOfMinutes * 0.12;
else if (hours >= 7 && hours <= 19)
charges = numberOfMinutes * 0.55;
else
charges = numberOfMinutes * 0.35;
cout << "The charge for the call is: $" << charges << endl;
return 0;
}