Program that calculates a water bill

I am not completely done with all the specs for the program but I can not get it to calculate anything but the constant variables SANITATION_FEE and STORM_WATER_FEE.

Here is a sample of what it should be doing:

Gallons Used = 16700
Meter size = 1.0

SANITATION_FEE = 20.41
STORM_WATER_FEE = 5.80
Base Water Charge for a 1.0 meter is = 6.14
Water cost = 41.79

Total = 74.14

I am not sue how to calculate water cost and base water charge in the function total cost. I cannot have any calculations in main and have to have at least three value returning functions.

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889`` ``````#include // library for input/output #include // console input/output #include // used for square root #include // Controls output formatting using namespace std; double TOTAL_COST(double, double, double); double METER_SIZE(double); int GALLONS_USED(double); const double SANITATION_FEE = 20.41; const double STORM_WATER_FEE = 5.80; int main() { // declaration section int account_number; double gallons_used; double meter_size; double water_cost; double base_water_charge; double water_per_gallon; double total_cost; // input section cout << "Enter your account number: " << endl; cin >> account_number; //processing section while(account_number != 000) { cout << "Enter your meter size: " << endl; cin >> meter_size; cout << "Enter your total gallons used: " << endl; cin >> gallons_used; base_water_charge = METER_SIZE(base_water_charge); gallons_used = GALLONS_USED(water_cost); total_cost = TOTAL_COST(total_cost, base_water_charge, water_cost); cout << total_cost << endl; } //output section _getch(); return 0; } double METER_SIZE(double base_water_charge) { double meter_size; if( meter_size == 0.625) base_water_charge = 3.61; else if( meter_size == 0.75) base_water_charge = 4.23; else if( meter_size == 1.0) base_water_charge = 6.14; return base_water_charge; } int GALLONS_USED(double water_cost) { int gallons_used; if( gallons_used <= 4000) water_cost = ( ( 4000 - gallons_used) * 0.00141 ); else if( gallons_used >= 4001 && gallons_used <= 10000) water_cost = ( (gallons_used - 4000) * 0.00231 + (4000 * 0.00141) ); else if( gallons_used >= 10001 && gallons_used <= 15000) water_cost = ( (gallons_used - 10000) * 0.00320 + (10000 - 4000) * 0.00231 + (4000 * 0.00141) ); else//( gallons_used > 15000) water_cost = ( (gallons_used - 15000) * 0.00370 + (15000 - 10000) * 0.00320 + (10000 - 4000) * 0.00231 + (4000 * 0.00141) ); return water_cost; } double TOTAL_COST(double total_cost, double base_water_charge, double water_cost) { total_cost = base_water_charge + water_cost + STORM_WATER_FEE + SANITATION_FEE; return total_cost; } ``````
In lines 39-41, you're calling functions and passing variables to them that are not only assigned but also not used in the function.
There's a few really, big problems that you need to look at and prevent in the future. I'll try to point out some examples.

In your METER_SIZE function:

 ``123`` `````` double meter_size; if( meter_size == 0.625) // ask yourself: what is the current value of meter_size? ``````

 ``123`` `````` int gallons_used; if( gallons_used <= 4000) // same thing here ``````

As for the functions inside of int main()

 ``1234`` `````` base_water_charge = METER_SIZE(base_water_charge); gallons_used = GALLONS_USED(water_cost); total_cost = TOTAL_COST(total_cost, base_water_charge, water_cost); // can you tell me the value of base_water_charge? ``````
Last edited on
Thanks, I will go back and look at it and hopefully fix the problems.
Topic archived. No new replies allowed.