Im working on a assignment and im having problems setting up the last function for this assignment which is the cost....This is what i have so far and this is the assignment... If someone could please give me some pointers i would greatly appreciate it..Thx
Write a function to calculate the cost to fill the pool as follows:
Calculate 1000’s of gallons by dividing the total gallons by 1000 and putting the result in an integer variable.
Use the following table to generate the cost:
Input: Gallons
Return Cost
Monthly Usage).... (Monthly Rate)
0 to 3,000 gallons.... $15.50 minimum
Above 3,000 gallons .... $2.90 per thousand
#include <iostream>
#include <cmath>
using namespace std;
Your function is to take gallons and return cost. Easy enough:
1 2 3 4 5
double CalcCost(double gal)
{
double cost;
...
}
The function should calculate the cost exactly as the assignment says:
Calculate 1000’s of gallons by dividing the total gallons by 1000 and putting the result in an integer variable.
...
0 to 3,000 gallons.... $15.50 minimum
Above 3,000 gallons .... $2.90 per thousand
So, if I have 1500 gallons, then (1500 <= 3000) and I pay 15.50 a month. return 15.5;
If I have 5100 gallons, then (5100 / 1000 --> 5) and (5 * 2.90 --> 15.50).
(It is a bit odd that you pay less for 3001 to 5999 gallons than you do for 3000 or less... but hey, follow the assignment.)
I imagine the problem means that for every thousand gallons above 3000 you pay $2.90 per 1000 over and including what you have paid for the first 3000 gallons???
If not - the imaginary business wouldn't last long - i imagine.