Having trouble finishing the if else statment. Help would be so greatly appreciated. Do i need more const? Just confused all and any information is apprieciated

  Input if home use, commercial use, or industrial use
    Clear screen
  IF (home use)
    $5.00 plus 0.0005 per gallon used
   else if (commercial use)
    $1000.00 for first 4 million gallons used and 0.00025 for each additional
   else //industry use
    $1000.00 if does not exceed 4 million but does not exceed 10 million;  and $3000.00 if exceeds 10 million gallons
    END IF
  Display reciept

So far this is the code i am able to come up with.

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

 void main ()
 {
    //local constants
    const char h                   = Code_Home;
    const char c                   = Code_Commercial;
    const char i                   = Code_Industrial;
               const float home               = $5.00
    const float home1              = $0.0005
    const float commercial         = $1000.00 
    const float commercial1        = $0.00025
    const float commercial2        = 4,000,000,000
    const float industrial         = $1000.00
    const float industrial1        = $2000.00
    const float industrial3        = $3000.00
    const int   industrial_gallons = 10,000,000,000

               //local variables
    int   Account_Num;       //Account number
                float Num_Gallons;       //Number of gallons used
    char  Code_letter;       //Code for bill
    /**************************start main program*********************/

    //Enter in bill type
    cout <<"\n\n\n\n\n\n\n\n" ;
    cout << setw (46) << "Bill Info";
    cout <<"\n\n\n" ;                             
    cout << setw (45) << "Enter Bill type : " ;
    cin  << Code_letter ;
    cout >> setw (45) << "Account Number : " ;
    cin  << Account_Num ;
    cout >> setw (45) << "Gallons Used : " ;
    cin  << Num_Gallons ;

    //Clear the screen
    system("cls");

    //Determine Reciept 
    if (Code_Home)
    {
        h = home + home1 * Num_Gallons ;
    }   
    else  
    {       
    if  (Code_Commercial)
    {
        c = commercial;
    }   
    else 
    {
        (Code_Industrial)
        i = ;
    }
    }

Recommended Answers

All 2 Replies

Your else if is a little flawed. Change it to.

if (Code_Home)
{
h = home + home1 * Num_Gallons ;
} 
else if (Code_Commercial)
{
c = commercial;
} 
else 
{
i = ; // not sure what your trying to do here
}

When writing multiple cases, use else if until you reach the final case.
By the way this is just the structure of the else if tree. You need to change some things to the code to get it run properly.

There are some more problems that I'd like to point out.
If I am understanding the problem correctly you want to test what BillType the user enters. To do this you need to use if else statements.

if(Code_Letter == h)
//do home calculation
else if(Code_Letter == c)
//do commercial calculation
else if(Code_Letter == i)
// do industrial calculation
else
//print error message for invalid input

Also you cant say

c = commercial;

c is a char variable and commercial takes on a float value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.