I'm a beginner, I need help please!!

This is my homework problem for my programming class, but I don't know how to write the code in C++ this problem is way too confusing!

Residential and business customers are paying different rates for water usage. Residential customers pay $0.004 per gallon for the first 8000 gallons. If the usage is more than 8000 gallons, the rate will be $0.007 per gallon after the first 8000 gallons. Business customers pay $0.005 per gallon for the first 10000 gallons. If the usage is more than 10000 gallons, the rate will be $0.009 per gallon after the first 10000 gallons. For example, if a business customer has used 12000 gallons, they need to pay $50 for the first 10000 gallons ($0.005 * 100000), plus $18 for the other 2000 gallons ($0.009 * 2000). Write a program to do the following. Ask the user which type the customer it is and how many gallons of water have been used. Calculate and display the bill.
You should start by thinking about the design of the program. What variables will you need? Probably one for type of user (residential or business), one for the residential gallons, another for the business gallons. Then a float variable for the residential rate and business rate.

Then think about getting user input, ask for type of user, then number of gallons.

Most people don't just hand out code on the forums because it's important to help you learn how to do it, but here is something to get you started.

1
2
3
4
5
char user; //get the type of user here
double rGallons; //get the number of gallons if residential
double bGallons; //get the number of gallons if business
float residentialRate; //note use of float because it involves decimal answers
float businessRate;

The following would be your if statement if 'r' is entered and gallons is under 8000:
1
2
3
4
if (rGallons < 8000) {
residentialRate = rGallons * 0.004; 
cout << "The water bill is $" << residentialRate << " for " << rGallons << " gallons."; 
}


For over 8000, think about the math.
Something like this would work:

1
2
3
4
5
6
if (rGallons > 8000) {
float rOver = rGallons - 8000;
residentialRate = (8000 * 0.004);
rOver = rOver * 0.007;
cout << "Bill is $" << residentialRate << for first 8000 plus $ << rOver << for the rest.";
} 


The math will be nearly identical for the business statements. Make sure your output meets the requirements you mentioned above, you may have to play with this a bit because a float variable won't round off penny's so an answer may be something like $34.545 instead of $34.45. This should be plenty of information to help get you started.

Last edited on
Can you do the math with paper and pencil?

What have you written so far? Remember to make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
Topic archived. No new replies allowed.