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

Revised to place the input, “work” and results in separate functions

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 PromptAndGet(const string& prompt);
float CalcBill(const float gallons);
void DisplayResults(const float TotalBill);

int main()
    {
    float consumption, total;

    cout << endl << "This program will compute your water and sewer bill." << endl;

    consumption = PromptAndGet("Please enter the number of gallons consumed: ");

    total = CalcBill(consumption);

    DisplayResults(total);

    return 0;
    }
float PromptAndGet(const string& prompt)
    {
    float input;
    cout << prompt;
    cin >> input;
    return input;
    }

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);
    }

void DisplayResults(const float TotalBill)
    {
    //output the results in a specific format
    cout.precision(2);
    cout.setf(ios::fixed);

    cout << endl << "The combined water and sewer bill is: $" << TotalBill << endl;
    return;
    }