A New Telephone Company has the following rate structure for long distance calls:
● The regular rate for a call is $0.10 per minute. (10 marks)
● Any call started at or after 6:00P.M. (1800 hours) but before 8:00A.M. (0800 hours) is
discounted 50 percent.
● Any call longer than 60 minutes receives a 15 percent discount on its cost (after any other
discount is subtracted).
● All calls are subject to a 4 percent federal tax on their final cost.
without using loops or functions
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int t, hr, min;
int start, end;
cout << "Enter time of a call start (military format): ";
cin >> t;
hr = t / 100;
min = t % 100;
start = hr*60 + min;
cout << "Enter time of a call end (military format): ";
cin >> t;
hr = t / 100;
min = t % 100;
end = hr*60 + min;
int duration = end - start;
if (duration < 0) {
duration += 24*60;
}
double cost;
cost = duration * 0.1;
// Night call discount
if (start < 8*60 || start >= 18*60) {
cost *= 0.5;
}
// Long call discount
if (duration > 60) {
cost *= 0.85;
}
cost *= 1.04; // Federal tax
cout << "Total cost is $" << fixed << setprecision(2) << cost;
return 0;
}
Comments
Leave a comment