Question: C++ I dont know what to do with the minutes for the military time; I dont know if the minutes matters? I also have some
C++ I dont know what to do with the minutes for the military time; I dont know if the minutes matters? I also have some 2 debugging issues like when I use the "switch (date)" and "||".
/*Write a program that computes the cost of a long-distance call. The cost of the call is determined according to the following rate schedule:
Calls started between 8:00 A.M. and 6:00 P.M., Monday through Friday, is billed at $0.45 per minute.
Calls starting before 8:00 A.M. or after 6:00 P.M., Monday through Friday, is charged at $0.21 per minute.
Any call started on a Saturday or Sunday is charged at a rate of $0.12 per minute.
The input will consist of the day of the week, the time the call started, and the length of the call in minutes.
The output will be the cost of the call.
1. The time is to be input in 24-hour notation, so the time 1:30 P.M. is input as 13:30
2. The day of the week will be read as one of the following two character string: Mo Tu We Th Fr Sa Su
3. The number of minutes will be input as a positive integer.
4. The assignment only cares about the start day/time of the call (you do not need to worry about it crossing over into another hour or day and having the rate change).
5. Assume all the input is typed in correctly.
Your questions can be any way you'd like, however the program must end with the price.
Below is an example interaction (the last line is the output):
Enter the day of the week using 2 characters (Mo Tu We Th Fr Sa Su): Mo
Enter the hour the call started, in 24-hour notation: 13
Enter the minute the call started: 30
Enter the length of the call in minutes: 60
Total cost: $27
*/
#include
using namespace std;
int main()
{
int timeOfCall, totalMin, min, hour, converToCents;
float dollar, cents;
const float weekendRate = .12;
const float weekdayRate = .45;
const float afterHrate = .21;
string date;
// screen I/O
cout << "Enter the day of the week using 2 characters (Mo Tu We Th Fr Sa Su): ";
cin >> date;
cout << "Enter the hour the call started, in 24-hour notation: ";
cin >> timeOfCall;
cout << "Enter the minute the call started: ";
cin >> min;
cout << "Enter the length of the call in minutes: ";
cin >> totalMin;
switch (date)
{
case "Sa":
case "sa":
case "Su":
case "su":
converToCents = (weekendRate * totalMin)*100;
dollar = (converToCents) / 100;
cents = (converToCents) % 100;
cout << "Total cost $" << dollar << "." << cents << endl;
break;
case "Mo":
case "mo":
case "Tu":
case "tu":
case "We":
case "we":
case "Th":
case "th":
case "Fr":
case "fr":
if ((timeOfCall < 8) || (timeOfCall > 18))
{
converToCents = (afterHrate * totalMin)*100;
dollar = (converToCents) / 100;
cents = (converToCents) % 100;
cout << "Total cost $" << dollar << "." << cents << endl;
}
else ((timeOfCall > 8) || (timeOfCall < 18))
{
converToCents = (weekdayRate * totalMin)*100;
dollar = (converToCents) / 100;
cents = (converToCents) % 100;
cout << "Total cost $" << dollar << "." << cents << endl;
}
break;
default: cout << endl;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
