Home > Mobile >  I made a c program to calculate tax but doesn't seem to work fine
I made a c program to calculate tax but doesn't seem to work fine

Time:12-05

Calculate income tax paid by an employee to the government as per the slabs mentioned below:

 Income slab         Tax 
  2.5L-5.0L            5%
  5.0L-10.0L           20%
  Above 10.0L          30%

here 2.5L means 250,000

#include <stdio.h>

int main()
{
    float tax = 0, income;
    printf("Enter your annual income\n");
    scanf("%f", &income);

    if (income >= 250000 && income <= 500000)
    {
        tax = tax   0.05 * (income - 250000);
    }
    if (income >= 500000 && income <= 100000)
    {
        tax = tax   0.20 * (income - 50000);
    }
    if (income > 100000)
    {
        tax = tax   0.30 * (income - 100000);
    }
    printf("Tax to be paid by you is Rs%f\n", tax);

    return 0;
}

CodePudding user response:

Looks like you're missing a few zeros. The line

income >= 500000 && income <= 100000

It is impossible for a value to be >= 500,000 and less than 100,000.

Did you mean 1,000,000? or 50,000?

Try this:

#include <stdio.h>

int main()
{
    float tax = 0, income;
    printf("Enter your annual income\n");
    scanf("%f", &income);

    if (income >= 250000 && income <= 500000)
    {
        tax = tax   0.05 * (income - 250000);
    }
    /// Changed "100000" to "1000000" in the following sections
    if (income >= 500000 && income <= 1000000)
    {
        tax = tax   0.20 * (income - 50000);
    }
    if (income > 1000000)
    {
        tax = tax   0.30 * (income - 1000000);
    }
    printf("Tax to be paid by you is Rs%f\n", tax);

    return 0;
}
  •  Tags:  
  • c
  • Related