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.

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <iostream> // library for input/output
#include <conio.h> // console input/output
#include <math.h> // used for square root
#include <iomanip> // 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:

1
2
3
    double meter_size;

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


1
2
3
    int gallons_used;

    if( gallons_used <= 4000) // same thing here 


As for the functions inside of int main()

1
2
3
4
        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.