// program 5: implement a decision structure for the following computation 
# include <iostream>
using namespace std;
//function used
void instruction ();

int main ()
{
    int income, tax,total;
            instruction();

// get the income 
cout << " input your income : $" <<endl;
cin  >> income;


if (income <= 15000)
{
           cout << " Pay no tax " << " your income is "<< income<< endl;
           }
           else if ( 15000 < income <= 44000)
           {
                tax = (income - 15000) * (20/100);
                total = income - tax;
                cout << " Your tax would be 20% on the amount in excess of $15000"<< endl;
                cout << " Your income after tax would be $ " << total << endl ;
                }
           else if ( 44000 < income <= 68150)
           {
                tax = ( 44000 * (22/100) + (income - 44000) * (28/100) );
                total = income - tax;
                cout << " Your income after tax would be $ " << total<< endl ;
                }
           else if ( 68150 < income <= 121300)
           {
                tax = (  58150*(28/100) + (income - 58150) * (31/100));
                total = income - tax;
                cout << " Your income after tax would be $ " << total<< endl ;
                }
           else if (121300< income<= 263750)

           {
                tax = (  121300*(31/100) + (income - 121300) * (36/100));
                total = income - tax;
                cout << " Your income after tax would be $ " << total<< endl ;
                }
             else if ( income> 263750)

           {
                tax = (  263750 *(36/100) + (income - 121300) * (39.6/100));
                total = income - tax;
                cout << " Your income after tax would be $ " << total<< endl ;
                }
system ("pause" );
return total;
return 0;
}
void instruction()

{ 
     cout << "This program compute gross and net salary . " << endl;
     
     }

I checked many times and the program does not have error. how ever, the result is really weird, I dont' know why it doesn't calculate

All the results it gives are as if tax is zero, right?

The reason is that you're doing everything with integer arithmetic. To look at an example;

else if ( 15000 < income <= 44000)
           {
                tax = (income - 15000) * (20/100);

With integer arithmetic (20 and 100 are integers) 20/100 will be computed as 0 (integer division). (income-15000)*0 will always yield zero.

Just add a decimal point behind each 100.

Just notice another problem. Instead of using :

else if ( 15000 < income <= 44000)

you should write it as something like:

else if ( (15000 < income) && (income <= 44000))

instead, for each of the "else-if" statement. Or else, all income greater than 15000 will go into the first "else-if" scope because the compiler will compute (15000 < income) as 1 (true), and then compute (1 <= 44000) as true.

else if ( (15000 < income) && (income <= 44000))

is more than you need to write.
The use of if...else if... will preclude having to retest for the preceding conditions, so you can simplify the code like

if (income <= 15000)
{
   //do something
}
else if ( income <= 44000 )  //income must be > 15000 in order to get here
{ 
   //do something  else
}
else if ( income <= 68150 )
{ 
  //you get the idea now?
}

And the last condition, where you're testing > 263750, is unnecessary. Just catch that with a final else.

Just add a decimal point behind each 100.

I dont' know if adding a decimal point behind each 100 mean 100.00. or 100.0 , cause I tried but the problem still there. thank you

oh, I got it ,thank you

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.