Stuck on a function.

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;

double CalcVolume(double length, double width, double depth);
double FeetToGallons(double FEET_TO_GALLONS, double volume);
double Price(double gal, double x);


int main()
{
const double FEET_TO_GALLONS = 7.48051948;
double length;
double width;
double depth;
double x = 1000;

double volume;
double gal;
double y;


cout << "Enter Length: ";
cin >> length;
cout << "Enter Width: ";
cin >> width;
cout << "Enter Depth: ";
cin >> depth;

volume = CalcVolume( length, width, depth);
gal = FeetToGallons(FEET_TO_GALLONS, volume);
y = Price(gal, x);


cout << "total is: " << volume << " cubic feet" << endl;
cout << "number of gallons are: " << gal << endl;
cout << "gallons: " << y << endl;
system("pause");
return 0;
}

double CalcVolume(double length, double width, double depth)
{
return ( length * width * depth);
}

double FeetToGallons(double FEET_TO_GALLONS, double volume)
{
return (FEET_TO_GALLONS * volume);
}
double Price(double gal, double x)
{
return ( gal / x);
}
Last edited on
.
Please use [code] tags..

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.)

Hope this helps.
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.

Dan
Topic archived. No new replies allowed.