/********************************************************************************************
3_27r1.cpp
    Jim Millard
    for CO311

Revised to place the “work” in a separate function

Simple program that calculates a bill based on formulae for water and sewer services
based on water consumption

********************************************************************************************/
#include <iostream>
#include <string>
using namespace std;

float CalcBill(const float gallons);

int main()
    {
    float consumption, total;

    cout << endl << "This program will compute your water and sewer bill." << endl;
    cout << "Please enter the number of gallons consumed: ";
    cin >> consumption;

    total = CalcBill(consumption);

    //output the results
    cout.precision(2);
    cout.setf(ios::fixed);
    cout << endl << "The combined water and sewer bill is: $" << totalCharge << endl;

    return 0;
    }
float CalcBill(const float gallons)
    {
    //handy named constants representing various rates
    const float waterRate = 0.021/100,
                sewerRate = 0.001/100,
              serviceRate = 0.02;

    //intermediate storage objects
    float waterCharge, sewerCharge, serviceCharge;

    waterCharge = waterRate * gallons;
    sewerCharge = sewerRate * gallons;
    serviceCharge = serviceRate * (waterCharge + sewerCharge);
    return (waterCharge + sewerCharge + serviceCharge);
    }