# Water Bill Program

Discussion in 'OT Technology' started by DweeLer, Nov 7, 2005.

1. ### DweeLerNew Member

Joined:
Aug 31, 2005
Messages:
3,222
0
Location:
Plano TX
I need help with this. [FONT=Verdana, Arial, Helvetica][FONT=Verdana, Arial, Helvetica]Its suppose to be like a water bill for commercial and home use. Home is 5.00+.0005 per gal and the commercial is 1000.00 (for 4 million gallons) and .00025 for every gallon after. The program prompts the user to enter a "C" or "H" for type of water bill, then how many gallons used, and it calculates and tell you how much the bill will be. If any other character is entered, it is suppose to return an error.

The math or something is wrong and It outputs this weird output:

Enter bill type (H = home, C = commercial): C
Enter gallons of water used: 100,000,001

**** WATER BILL ****
Account Type: Commercial
Total Amount Owed: 10000x4375b4

[/FONT][/FONT]

Joined:
Nov 13, 2001
Messages:
11,861
0
Location:

3. ### DweeLerNew Member

Joined:
Aug 31, 2005
Messages:
3,222
0
Location:
Plano TX
#include <iostream>
#include "conio.h"

using namespace std;

const double HOUSEPGAL = 0.0005;
const double HOUSEINIT = 5.00;
const long FOURMIL = 4000000;
const double COMINIT = 1000.00;

int getBill (char);

int main()
{
char x;
long g;
double result;

cout << "Enter bill type (H = home, C = commercial): ";
cin >> x;
cout << "Enter gallons of water used: ";
cin >> g;
cout << endl;

switch(getBill (x))
{

case 0: result = g*HOUSEPGAL+HOUSEINIT;
cout << "**** WATER BILL ****";
cout << endl;
cout << "Account Type: Home";
cout << endl;
cout << "Total Amount Owed: " << result <<
cout << endl;
break;
case 1: if (g<FOURMIL)
{
result = COMINIT;
}
else if (g>FOURMIL)
{
}
cout << "**** WATER BILL ****";
cout << endl;
cout << "Account Type: Commercial";
cout << endl;
cout << "Total Amount Owed: " << result <<
cout << endl;
break;
break;
}

getch();
return 0;
}

int getBill (char x)
{
if(x == 'c' || x == 'C')
return 1;
else if (x == 'h' || x == 'H')
return 0;
else
return 2;
}

4. ### peterthesmartNew Member

Joined:
Aug 9, 2004
Messages:
76
0
Location:
Minnesota
Make all the variables longs? There may be a problem when it multiplies doubles with longs.

Joined:
Aug 31, 2005
Messages:
3,222