Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with an if statement!!!

Status
Not open for further replies.

KPlateo

Programmer
Mar 14, 2001
6
US
using djgpp on win 98, hid_places_f2[0] = 1, hid_places_f2[1] = 2, this always prints the message at the end, even if y is equal to -1,and i don't want it to, think i amde an error, if you could help out please.

int y = 0;
y = hid_places_f2[0] - hid_places_f2[1];
if ( (y % 3) != 0 || y != 1 || y != -1 )
printf("%d%d%d%dwrong", y, hid_places_f2[0], hid_places_f2[1], hid_places_f2[2]);
 
try using && instead of ||, I t hink you've got a logic error.

Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
i think the problem in , (..||y != 1 ||...)
this part is logical true(since y = -1 according to ur numbers,and so it is not 1,so y!=1 is ture)...
try what they said to u(use &&)
 
one more i wanna add
you should put the brackets for each expression
if ( ((y % 3) != 0) || (y != 1) || (y != -1) )

hope help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top