Answer to Question #15430 in C++ for Simon

Question #15430
Write a C program that will calculate and print out the bills for the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of h means home use, a code of c means commercial use, and a code of i means industrial use
• Code h: RM5.00 plus RM0.0005 per gallon used
• Code c: RM1000.00 for the first 4 million gallons used and RM0.00025 for each additional gallon
• Code i: RM1000.00 if usage does not exceed 4 million gallons; RM2000.00 if usage is more than 4 million gallons but does not exceed 10 million gallons; and RM3000.00 if usage exceeds 10 million gallons

Your program should prompt the user to enter an account number (type int), the code (type char) and the gallons of water used (type double). Your program should echo the input data and print the amount due from the user.
1
Expert's answer
2012-09-27T10:52:46-0400
#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;

int main()
{
int account;
char code;
double gallons, bill;

cout << "Enter your account number:" << endl;
cin >> account;

cout << "Now enter your code(h,c, or i):" << endl;
cin >> code;

cout << "Now enter the amount of gallons of water used:" << endl;
cin >> gallons;

if (code == 'h')
{
bill = 5 + (gallons * 0.0005);
}
if (code == 'c' && gallons > 4000000)
{
bill = 1000 + ((gallons - 4000000) * 0.00025);
}
else if (code == 'c' && gallons <= 4000000)
{
bill = 1000;
}
if (code == 'i' && gallons <= 4000000)
{
bill = 1000;
}
else if (code == 'i' && gallons < 4000000 && gallons >
10000000)
{
bill = 2000;
}
else if (code == 'i' && gallons >= 10000000)
{
bill = 3000;
}

cout << "The bill for account number: " << account << ", will be: $" << bill
<< endl;
getch();
return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Kobi
13.09.20, 16:09

Your program is helpful

Assignment Expert
29.10.14, 10:04

Dear Guy, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!

Guy
29.10.14, 00:00

thank you, kind sir

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS