Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

closed why my programe give error??

+5 votes
asked Nov 14 by dhrup kr sinha (270 points)
closed Nov 19 by Admin
#include <stdio.h>

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

  if (income >= 250000 && <=500000)
    {
      tax = tax + 0.05 * (income - 250000);
    }
  if (income >= 500000 && <=1000000)
    {
      tax = tax + 0.20 * (income - 500000);
    }
  if (income >= 1000000)
    {
      tax = tax + 0.30 * (income - 1000000);
    }

  printf ("\n your net income tax to be paid by 26th of this month is %f", tax);
    
    return 0;
}
closed with the note: answered

3 Answers

+2 votes
answered Nov 15 by Marcoo Petroino (480 points)
selected Nov 15 by dhrup kr sinha
 
Best answer

When you are comparing more than one expression using a comparison operator you need to always specify the variable you want to compare. 

Here is the correct way: 

if (income >= 250000 && income <= 500000) {...}

commented Nov 15 by dhrup kr sinha (270 points)
thank you so much.
commented Nov 15 by Med OX (110 points)
you should repet your variable when you have mmore than one exprisson.
+1 vote
answered Nov 15 by Peter Minarik (40,320 points)

The less than (<=) operator needs two operands. You only provided one.

Your code correctly is as below:

#include <stdio.h>

int main ()
{
    float tax = 0, income;
    printf ("Enter your income:\n");
    scanf ("%f", &income);
    
    if (income >= 250000 && income <=500000)
    {
        tax = tax + 0.05 * (income - 250000);
    }
    if (income >= 500000 && income <=1000000)
    {
        tax = tax + 0.20 * (income - 500000);
    }
    if (income >= 1000000)
    {
        tax = tax + 0.30 * (income - 1000000);
    }
    
    printf ("\n your net income tax to be paid by 26th of this month id %f", tax);
    return 0;
}
commented Nov 15 by dhrup kr sinha (270 points)
Thank you so much.
0 votes
answered Nov 19 by Vikram Kumar (140 points)

 if (income >= 250000 && <=500000)
    {
      tax = tax + 0.05 * (income - 250000);
    }

you have to provide comparison parameter for comparison .

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...