i need help with if statement. for some reason its not working right and i dont know why. i never goesinside 2nd if statement.
i

i want to go inside this if statement - if left_var value is "2x"

//for loop iam start with x. b = 'x'  and b-1 != '+','-'

if(left_var[b] == 'x' && (left_var[b-1] != '+' || left_var[b-1] != '-'))

i want to go inside this if statement if - if left_var value is "-x"

if(left_var[b] == 'x' && (left_var[b-1] == '+' || left_var[b-1]== '-'))

full code

void variables_to_num(char left_var[], char left_var_num[])
{
  int b = 0;
  int lv = 0;

  int flag = 0;


   for(b = 50 - 1; b > -1; b--)
    {
      if(left_var[b] != '\0')
        {
          if(left_var[b] == 'x' && (left_var[b-1] != '+' || left_var[b-1] != '-'))
            {

             } 
             if(left_var[b] == 'x' && (left_var[b-1] == '+' && left_var[b-1]== '-'))
            {
              //doesnt go here
            }
       }
   }


 }

This section of your code:

if(left_var[b] == 'x' && (left_var[b-1] != '+' || left_var[b-1] != '-'))
{
    /*the second condition of this if statement is currently useless. for whatever
      value of left_var[b-1], it will always be unequal to EITHER '+' or '-'

      I'm assuming you intended to use && here*/
} 
if(left_var[b] == 'x' && (left_var[b-1] == '+' && left_var[b-1]== '-'))
{
    /*since left_var[b-1] can have only 1 value, it cannot be both '+' and '-'
      however, the second part of your condition requires left_var[b-1] equal to
      '+' AND at the same time equal to '-', so for whatever value given, lines
      in this if statement will not be executed, ever.

      I'm assuming you intended to use || here*/
}
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.