The && operator

I'm having a problem with this code. If both items are true, I want the first line to run, but if one of the items are false, I want the "else" to run. Ive run through this and I know that both are not always true, but its not kicking over to else. Any suggestions?

1
2
3
4
5
6
7
8
9
10
  if((xCol[num3] == xCol[num2]) && (yCol[num3] == yCol[num2]))
	{
		outFile << "Inj-" << injPoint;
	} 
	else
	{
		outFile << "Inj-" << injPoint+1;
		injPoint++;
	}
If both items are true, I want the first line to run, but if one of the items are false, I want the "else" to run.


That is what && does. You are using it correctly.

Ive run through this and I know that both are not always true, but its not kicking over to else.


How do you know this? You must be mistaken.

Either both conditions are always true, or the else is running without you realizing it. Or this code isn't running at all.

In these cases it helps to step through the code with a debugger to make sure it's actually doing what you expect it to be doing.
Last edited on
Topic archived. No new replies allowed.