I seem to be having a silly issue with an IF statement that I can't figure out. I'm quite new to C++ but not to code in general. I understand how logical statements work but I might be missing something here.
Just so there's no confusion. I'm trying to create a basic draughts/checkers game and the function in question is being called to move the correct piece as referrence by a grid:
1 2 3 4 5 6 7 8
The code checks the first element of the "position_from" array and looks for a letter (A-H). If it finds any of these it will then continue in to a nested loop and check for 1-8 to complete the grid referrence.
I've only just begun so only have code which checks for 'A', then continues in to a loop and checks for 1-8. My problem is, the nested IF statement I am using within the loop, has no other option but to come true, but for some reason won't.
The following code will output:
As you can see from the output, element does indeed contain the number 1. With that in mind, why is the following code not working? The for loop checks 'position_from' (which equals '1') against 'I', which equals 0 on the first loop then 1 on the second loop, then stops looping.
Originally Posted by Code output
void move_piece(char *pieces, char *position_from, char *position_to)
if(position_from == 'A')
cout << "True - 'position_from' does equal 'A'" << endl;
for(int i = 0; i < 2; i++)
if(position_from == i) /* This statement must come true once */
cout << "True - 'position_from' does equal 1";
cout << i << " = ";
cout << position_from[i] << endl;
cout << "False - 'position_from does not equal 'A'";
Help is much appreciated. Thanks.