Hi. I'm looking for some help figuring out the final step in my code. Here are the instructions:
---------------
The phone company uses the following rate structure for calls from San Francisco to Seattle, Washington:
Any call started at or after 6:00 pm (1800) but before 8:00 am (800) is discounted 50%.
All calls are subject to a 4% federal tax.
The regular rate is $0.35 per minute.
Any call longer than 60 minutes receives a 16% discount on its cost (after any other discount is subtracted but before tax is added).
Write a program that reads from the user the start time for a call based on a 24-hour clock and the length of the call in minutes. The gross cost (before any discount or tax) should be printed, and then the net cost (after discounts and taxes). Turn in 4 outputs for this exercise, showing that your program works in each of the following 4 cases. Use the input examples shown here, don't make up your own.
-------------
I got almost everything working great with this, and my gross cost is calculating fine. However, I am having a problem with the net cost. I cannot figure out how to get the formula right so that it calculates correctly. Any ideas on how I can fix it? Thanks!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
// This program calculates the cost of long-distance calls.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
double pricePerMinute = 0.35; //Regular price per minute with no discounts
double callCost;
double grossCost;
double netCost;
int numberOfMinutes;
int startTime;
//Get user information
cout << "Enter start time: ";
cin >> startTime;
cout << "Enter length of call in minutes: ";
cin >> numberOfMinutes;
//Rate structures for calls.
if (startTime >= 801 && startTime <= 1759)
callCost = pricePerMinute;
else if (startTime >= 1800 && startTime <= 800)
callCost = (50.0 / pricePerMinute);
else if (numberOfMinutes >= 60)
callCost = (16.0 / pricePerMinute);
//Calculations.
grossCost = numberOfMinutes * pricePerMinute;
netCost = callCost + (callCost * 0.04);
//Display answers.
cout << fixed << showpoint << setprecision(2);
cout << "Gross cost: $ " << grossCost << endl;
cout << fixed << showpoint << setprecision(2);
cout << "Net Cost: " << netCost << endl;
return 0;
}
|