/********************************************************************************************
3_27r2.cpp
Jim Millard
for CO311
Revised to place the 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 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;
cout << "Please enter the number of gallons consumed: ";
cin >> consumption;
total = CalcBill(consumption);
DisplayResults(total);
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);
}
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;
}