# Source Code for determining water bill calculation

Page 1 of 1

## 3 Replies - 6691 Views - Last Post: 12 November 2009 - 10:18 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=138725&amp;s=facf1ae705d315a7e6fe2b7b0e108353&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 honumike

Reputation: 0
• Posts: 4
• Joined: 12-November 09

# Source Code for determining water bill calculation

Posted 12 November 2009 - 08:37 PM

I have this code that is meant to determine how to charge a homeowner for a water bill by certain usage. The code is included and complies, but does not perform calculations. What am I not doing here? Code follows:

```#include <iostream>
using namespace std;

void main()//should this be int main?
{
int Amount;
double Charge;
cout << "Enter number of cubic feet \n ";
cin >> Amount;
cin. ignore();

if (Amount <= 1000)// I had previously inserted braces after the ) and again after 15.00;
Charge = 15.00;

else (Amount <= 2000); // I had else if here at one point and it did not work
Charge = .0175 * Amount;

if (Amount <= 3000)
Charge = .02 * Amount;

else  Charge = 70.00; // There was a cin.get(); following this last else but it did not work

}

```

** Edit **

Is This A Good Question/Topic? 0

## Replies To: Source Code for determining water bill calculation

### #2 no2pencil

• Professor Snuggly Pants

Reputation: 5967
• Posts: 29,150
• Joined: 10-May 07

## Re: Source Code for determining water bill calculation

Posted 12 November 2009 - 08:41 PM

honumike, on 12 Nov, 2009 - 09:37 PM, said:

```void main()//should this be int main?

```

Yes. But you'll also need to give it a return type because you are declaring it to return int, & so it will then need to.

In your code above, you gather the users input, & you calculate it. But what do you want it to do from there?

### #3 honumike

Reputation: 0
• Posts: 4
• Joined: 12-November 09

## Re: Source Code for determining water bill calculation

Posted 12 November 2009 - 09:13 PM

no2pencil, on 12 Nov, 2009 - 07:41 PM, said:

honumike, on 12 Nov, 2009 - 09:37 PM, said:

```void main()//should this be int main?

```

Yes. But you'll also need to give it a return type because you are declaring it to return int, & so it will then need to.

In your code above, you gather the users input, & you calculate it. But what do you want it to do from there?

I wan't it to tell me which method of billing will be appropriate. It will be one of the four listed. I had the main as "int" but it did not work either.

### #4 OliveOyl3471

• Everybody's crazy but me!

Reputation: 135
• Posts: 6,581
• Joined: 11-July 07

## Re: Source Code for determining water bill calculation

Posted 12 November 2009 - 10:18 PM

You want it to tell you...? You mean, you want something printed? Then you use cout:
```#include <iostream>
using namespace std;

int main()//should this be int main?
{
int Amount;
double Charge;
cout << "Enter number of cubic feet \n ";
cin >> Amount;
cin. ignore();

if (Amount <= 1000)// I had previously inserted braces after the ) and again after 15.00;
Charge = 15.00;

else if (Amount <= 2000) // I had else if here at one point and it did not work
//you were right to use else if, but remove the semicolon...and using curly braces {} is better
//though it does work without them, as long as the else includes only one line
Charge = .0175 * Amount;

else if (Amount <= 3000)
Charge = .02 * Amount;

else  Charge = 70.00; // There was a cin.get(); following this last else but it did not work

cout<<"Charge is: "<<Charge<<endl;
system("Pause"); //pause to see output
return 0; //because int main must return an int
}

```