-
Array in if condition.
Hi,
Sorry if this seems insignificant but I am not very good. I can't get this code to work:
Code:
for(i=0; i<=10; ++i){
if (hand[i]==card){
x=1;
}
else{
x=0;
}
}
I have got the program to print the values of the variables, and everything is as I would expect. The program runs through the loop and the if statement, but refuses to recognize when hand[i]==higher_card, even though it can print them out, and they are clearly the same. All of the variables are integers. Can anyone help?
-
There is nothing inherrently wrong with the code posted.
You'll need to show more.
-
That's the only code in this function. The function is passed hand and card, but since it can print these out correctly I figured there was nothing wrong with how I passed them. The elements of hand are read in from a file (they are definitely integers though). Do you think there might be some sort of space or end of line character or something that's the problem?
-
How is card defined? How is hand defined? Please show a complete program that illustrates your problem.
Jim
-
The whole program is to big to show, I'll try and find what's relevant and post it as soon as I can. Thanks for your help with this.
-
Aha, I've just found where I've gone wrong. The whole thing was immersed in if statements and loops, and I wasn't following it properly. Thank you for helping :) I feel a bit embarrassed now....