|
-
August 18th, 2010, 10:43 PM
#1
Will this code work?
here is the problem:
Allenton Water Department wants a program that calculates a customers monthly water bill. The clerk will enter the current and previous meter readings. The program should calculate and display the number of gallons of water used and the total charge for the water. The charge for water is $7 per 1000 gallons. However, there is a minimum charge of $16.67. ( in other words, every customer must pay at least $16.67)
does this code make sense?
//ch5 - 13.cpp : calculates and displays number of gallons & total charge for the water
//created/revised by <> on <8-18-10>
#include <iostream>
using namespace std;
int main()
{
//declare variables
float previousReadings = 0.0;
float currentReadings = 0.0;
float gallonsUsed = 0.0;
float totalCharge = 0.0;
//enter input items
cout <<"Enter the current readings:";
cin >> currentReadings;
cout <<"Enter the previous readings:";
cin >> previousReadings;
//calculates the gallons used
gallonsUsed = currentReadings - previousReadings;
//calculates the total charge
if (totalCharge >= 16.67)
{
totalCharge = (gallonsUsed / 1000.0) *7.0;
cout <<"totalCharge:" << totalCharge << endl;
}
else
{
totalCharge = 16.67;
cout <<"total charge:" << totalCharge << endl;
}
//end if
cout <<"gallons used:" << gallonsUsed << endl;
cout <<"total charge:" << totalCharge << endl;
return 0;
} //end of main function
Last edited by ade161; August 19th, 2010 at 05:42 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|