What am I missing to in this function to terminate the processing and print an error message if there is a wrong meter size input? Here is code:
//Header Files
#include <iostream> //needed for cin and cout chpt. 3
#include <conio.h> //needed for getch( )
#include <string> //needed for string
using namespace std;
double FindWaterCharge(double, double); //function prototype, similair to function heading chpt. 3
double FindSewerCharge(double , double , double); //function heading chpt. 3
double FindTotalCost(double, double, double, double); //function prototype, similair to function heading chpt. 3
//If I needed to declare constants I would declare them here, all upper case with _ b/w words
const double SANITATION_FEE = 20.41; //
const double STORM_WATER_FEE = 5.80; //
const double SEWER_PER_GALLON = .00372;
int main( )
{
//Declaration section
double meterSize; //size of meter at resident
double gallonsUsed; //total gallons used
double totalCost; //total cost of the water bill
double waterCharge; //total cost of the water charge on the bill
double sewerCharge; //total cost of the sewer charge on the bill
string accountNumber; //string for the account number
//Input section
cout << "Enter the account number" << endl;
cin >> accountNumber;
cout << "Enter the meter size" << endl;
cin >> meterSize;
cout << "Enter the gallons used" << endl;
cin >> gallonsUsed;
cout << endl << endl;
//Output section
cout << "The account number is: " << accountNumber << endl;
cout << "The number of gallons used is: " << gallonsUsed << endl;
cout << "The total water charge is: $" << waterCharge << endl;
cout << "The total sewer charge is: $" << sewerCharge << endl;
cout << "The total amount of the bill is: $" << totalCost << endl;
getch( );
return 0;
}
double FindWaterCharge(double meterSize, double gallonsUsed) //function heading chpt. 3
//Preconditions: The value of meterSize and gallonsUsed is known
//Postconditions: The total cost of the water charge in the bill is returned
{
double baseWater;
double waterPerGallon;
return (baseWater + (waterPerGallon * gallonsUsed));
}
double FindSewerCharge(double meterSize, double gallonsUsed, double SEWER_PER_GALLON) //function heading chpt. 3
//Preconditions: The value of meterSize, gallonsUsed and SEWER_PER_GALLON are known
//Postconditions: The total cost of the sewer charge in the bill is returned
{
double baseSewer;
return (baseSewer + (gallonsUsed * SEWER_PER_GALLON));
}
double FindTotalCost(double waterCharge, double sewerCharge, double SANITATION_FEE, double STORM_WATER_FEE) //function heading chpt. 3
//Preconditions: The value of waterCharge, sewerCharge, SANITATION_FEE and STORM_WATER_FEE are known
//Postconditions: The total cost of the bill is returned
{
return waterCharge + sewerCharge + SANITATION_FEE + STORM_WATER_FEE;
}
Here is what I modified in the code and it seamed to work. I don't know if this is the most efficient way to do it. Based on the parameters of the assignment in which that I cannot have anything printed in the value-returning function, it seams that your solution wouldn't work. Not that it wouldn't work, but saying for this assignment it wouldn't. Thank you for your help though and let me know what you think or if you found a better way.
//Header Files
#include <iostream> //needed for cin and cout chpt. 3
#include <conio.h> //needed for getch( )
#include <string> //needed for string
using namespace std;
double FindWaterCharge(double, double); //function prototype, similair to function heading chpt. 3
double FindSewerCharge(double , double , double); //function heading chpt. 3
double FindTotalCost(double, double, double, double); //function prototype, similair to function heading chpt. 3
//If I needed to declare constants I would declare them here, all upper case with _ b/w words
const double SANITATION_FEE = 20.41; //
const double STORM_WATER_FEE = 5.80; //
const double SEWER_PER_GALLON = .00372;
int main( )
{
//Declaration section
double meterSize; //size of meter at resident
double gallonsUsed; //total gallons used
double totalCost; //total cost of the water bill
double waterCharge; //total cost of the water charge on the bill
double sewerCharge; //total cost of the sewer charge on the bill
int counter; //counter needed to either end program or continue based on meter size input correction
string accountNumber; //string for the account number
//Output section
while ((meterSize == 0.625 || meterSize == .625 || meterSize == 0.75 || meterSize == .75 || meterSize == 1.0 || meterSize == 1) && counter < 1)
{
counter++;
cout << "The account number is: " << accountNumber << endl;
cout << "The number of gallons used is: " << gallonsUsed << endl;
cout << "The total water charge is: $" << waterCharge << endl;
cout << "The total sewer charge is: $" << sewerCharge << endl;
cout << "The total amount of the bill is: $" << totalCost << endl << endl;
}
if (counter == 1)
cout << endl;
else
cout << "Error in meter size";
getch( );
return 0;
}
double FindWaterCharge(double meterSize, double gallonsUsed) //function heading chpt. 3
//Preconditions: The value of meterSize and gallonsUsed is known
//Postconditions: The total cost of the water charge in the bill is returned
{
double baseWater;
double waterPerGallon;
return (baseWater + (waterPerGallon * gallonsUsed));
}
double FindSewerCharge(double meterSize, double gallonsUsed, double SEWER_PER_GALLON) //function heading chpt. 3
//Preconditions: The value of meterSize, gallonsUsed and SEWER_PER_GALLON are known
//Postconditions: The total cost of the sewer charge in the bill is returned
{
double baseSewer;
return (baseSewer + (gallonsUsed * SEWER_PER_GALLON));
}
double FindTotalCost(double waterCharge, double sewerCharge, double SANITATION_FEE, double STORM_WATER_FEE) //function heading chpt. 3
//Preconditions: The value of waterCharge, sewerCharge, SANITATION_FEE and STORM_WATER_FEE are known
//Postconditions: The total cost of the bill is returned
{
return waterCharge + sewerCharge + SANITATION_FEE + STORM_WATER_FEE;
}