View Single Post
  #10 (permalink)  
Old November 7th, 2005, 08:51 PM
Paramesh Paramesh is offline
Authorized User
 
Join Date: Nov 2005
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to Paramesh
Default

Sorry middledd.
I didnt take a look at the updated program.

Quote:
quote:I honestly was surprised that compiled.
The lines:
Code:
                        cout << "Total Amount Owed: " << result <<
                        cout << endl;   
can be viewed like this:
Code:
                        cout << "Total Amount Owed: " << result << cout << endl;   
So, printing cout will return the address.

Dweeler, you should change your code as shown by middledd.
So, your code should be like this:
Code:
#include <iostream> // to read cin, cout
#include "conio.h"
#include <iomanip>

using namespace std;

// CONSTANTS

const double HOUSEPGAL = 0.0005; //Constant for price per gallon on house
const double HOUSEINIT = 5.00; //house initial price
const double FOURMIL = 4000000; //Commercial amount for 1000
const double COMINIT = 1000.00; //Commercial initial price for water
const double COMADDGAL = 0.00025; //Commercial price for additional gallon

int getBill (char);

//main

int main()
{
    //variables
        char x;
        double Gal;
        double result = 0;

            cout << fixed << showpoint;

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


        switch(getBill (x))
        {
                //case 0 is for the House Bill
                case '0': result = (Gal * HOUSEPGAL)+ HOUSEINIT;
                        cout << "**** WATER BILL ****";
                        cout << endl;
                        cout << "Account Type: Home";
                        cout << endl;
                        cout << setprecision(1);
                        cout << "Total Amount Owed: " << result << endl;     
                        cout << "  Thank you for your business.";
                        cout << endl;
                        cout << "********************";
                                break;
                //case 1 is for the Commercial Bill
                case '1': if (Gal < FOURMIL)
                        {
                        result = COMINIT;
                        }
                        else if (Gal > FOURMIL)
                        {
                        result = (Gal - FOURMIL)* COMADDGAL + (Gal * COMINIT);
                        }
                        cout << "**** WATER BILL ****";
                        cout << endl;
                        cout << "Account Type: Commercial";
                        cout << endl;
                        cout << setprecision(1);
                        cout << "Total Amount Owed: " << result;
                        cout << endl;     
                        cout << "Thank you for your business.";
                        cout << endl;
                        cout << "********************";
                                break;
                //case 2 is for the error part
                case '2': cout << "Error. Please ask for assistance.";
                                break;
        }

        return 0;
}

//how the program chooses which case to go with based on the character input
int getBill (char x)
{
        if(x == 'c' || x == 'C')
                return '1';
        else if (x == 'h' || x == 'H')
                return '0';
        else
                return '2';
}
Regards,
Paramesh.

"Don't walk behind me; I may not lead.
Don't walk in front of me; I may not follow.
Just walk beside me and be my friend."
Reply With Quote