# include <iostream.h>
# include <conio.h>
int main()
{

float income=0;


int tax=0;

  float  r1=0.0;
  float  r2=0.1;
  float  r3=0.2;
  float  r4=0.3;
  float  r5=0.4;
  float  r6=0.5;
cout<<"Enter income:";
cin>>income;    



if(income>=100,001)
   tax=income*r6;
else if(income<=100,000 && income >=70,001)
    tax=income*r5;
else if(income>=70,000 && income >=50,001)
    tax=income*r4;
else if(income>=50,000 && income >=30,001)
    tax=income*r3;
else if(income>=30,000 && income >=10,001)
    tax=income*r2;
else if(income>=10,000 && income >0)
    tax=income*r1;

cout<<"Income tax is :"<<tax;

getch() ;
}
`if(income>=100,001)
tax=income*r6;
else if(income<=100,000 && income >=70,001)
tax=income*r5;
else if(income>=70,000 && income >=50,001)
tax=income*r4;
else if(income>=50,000 && income >=30,001)
tax=income*r3;
else if(income>=30,000 && income >=10,001)
tax=income*r2;
else if(income>=10,000 && income >0)
tax=income*r1;`

Remove the commas... in your conditional expression...

You write 100,000 as 100000
and same goes for the rest

In what way isn't it working? Does it fail to compile? Do you get any error or warning messages? Does it run and crash? Does it give the wrong values? We really need more details in your initial post in order to help you.

BTW, two things you should know. First off, the <conio.h> header is non-standard, and specific to certain MS-DOS and Windows compilers. You would be better off avoiding it entirely. Second, the <iostream.h> header is an obsolete form; the C++98 standard redefined all the standard headers to remove the '.h' extension, and add a 'c' to the beginning of the older C library headers. For compilers released after 1999, you should always use <iostream>, and similarly, use headers such as <cstdlib> instead of <stdlib.h>. Just something to be aware of. You also need to scope the standard library functions and classes as being in the std namespace, so you need to either add using namespace std; to the beginning of your program, or else explicitly scope them using std:: - for example, you would have std::cout instead of just cout.

Edited 3 Years Ago by Schol-R-LEA

Your biggest problem is including commas in the number. While visually appealing, it doesn't return the right value.

Your second biggest problem is your setting the limits of each if statement with 2 greaterthan or equals signs, instead of greater than or equal for the lower limit and less than or equal for the upper limit or getting rid of the lower limit, since it becomes redundant with the upper limit using greater than or equal.

As for the rest, even if your instructor insists on using out dated software, it would make sense to do your coding with more up to date software and learn to break some bad habits. Both Code:Blocks and VC++ Express are viable options for upgrading.

Edited 3 Years Ago by tinstaafl

I was hoping to coax the OP into solving the issue, or at the very least go over the specific problems it had with us explicitly, but oh well.

If it helps any (which I doubt, but who knows), here is how I would solve this problem:

#include <iostream>

struct TaxRate
{
    int bracket;
    double rate;
};


int main()
{
    float income = 0;
    float tax = 0;


    const TaxRate tr[6] = {
        {0, 0.0},
        {10000, 0.1},
        {30000, 0.2},
        {50000, 0.3},
        {70000, 0.4},
        {100000, 0.5}};

    std::cout << "Enter income: ";
    std::cin >> income;

    if (income > tr[5].bracket)
    {
        tax = income * tr[5].rate;
    }
    else
    {
        for (int i = 5; i > 0; i--)
        {
            if (income > tr[i-1].bracket && income <= tr[i].bracket)
            {
                tax = income * tr[i-1].rate;
                break;
            }
        }
    }

    std::cout << "Income tax is :" << tax << std::endl;

    return 0;
}

Since you're course probably hasn't covered arrays and structs yet, and might not even have covered loops yet for all I know, this isn't going to help you in your particular assignment, but it might give you some idea of how to solve it in a bit more professional manner.

Comments
thanks
Nice code

the numbers in the If condition should not have commas(,)

# include <iostream.h>
# include <conio.h>
int main()
{
   float income=0;
   int tax=0;
   float  r1=0.0;
   float  r2=0.1;
   float  r3=0.2;
   float  r4=0.3;
   float  r5=0.4;
   float  r6=0.5;
   cout<<"Enter income:";
   cin>>income;    
   if(income>=100001)
     tax=income*r6;
   else if(income<=100000 && income >=70001) 'error lines start...
     tax=income*r5;
   else if(income>=70000 && income >=50001)
     tax=income*r4;
   else if(income>=50000 && income >=30001)
     tax=income*r3;
   else if(income>=30000 && income >=10001) 'error lines end...
     tax=income*r2;
   else if(income>=10000 && income >0)
     tax=income*r1;
   cout<<"Income tax is :"<<tax;
   getch() ;
}

Line 26 of the OP code else if(income>=70,000 && income >=50,001) coulde be written as else if( income >=50001)
Same for the rest of the else ifs

You can't put comma in floating point variable value whether it is in if condition or in assignment.

This article has been dead for over six months. Start a new discussion instead.