Water Bill Program

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

  1. DweeLer

    DweeLer New Member

    Joined:
    Aug 31, 2005
    Messages:
    3,222
    Likes Received:
    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
    Thank you for your business.

    the files are on my site, listed below. please help.

    http://www.bradh.net/jacob/prog/
    [/FONT][/FONT]
     
  2. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
    post your code, im too lazy to click on a link and download it.
     
  3. DweeLer

    DweeLer New Member

    Joined:
    Aug 31, 2005
    Messages:
    3,222
    Likes Received:
    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;
    const double COMADDGAL = 0.00025;

    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;
    cout << "Thank you for your business.";
    break;
    case 1: if (g<FOURMIL)
    {
    result = COMINIT;
    }
    else if (g>FOURMIL)
    {
    result = (g-FOURMIL)*COMADDGAL+(g*COMINIT);
    }
    cout << "**** WATER BILL ****";
    cout << endl;
    cout << "Account Type: Commercial";
    cout << endl;
    cout << "Total Amount Owed: " << result <<
    cout << endl;
    cout << "Thank you for your business.";
    break;
    case 2: cout << "Error. Please ask for assistance.";
    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. peterthesmart

    peterthesmart New Member

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

    DweeLer New Member

    Joined:
    Aug 31, 2005
    Messages:
    3,222
    Likes Received:
    0
    Location:
    Plano TX
    still gives me some weird result. anyone? its due tomorrow.
     

Share This Page