We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,220 Members — Technology Publication meets Social Media

# if statement help plz

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
}
}
}

}

2
Contributors
1
59 Minutes
Discussion Span
1 Year Ago
Last Updated
2
Views
hwoarang69
Posting Pro
569 posts since Feb 2012
Reputation Points: 6
Skill Endorsements: 7

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*/
}

scudzilla
Posting Whiz
320 posts since Mar 2007
Reputation Points: 27