I am trying to make a connect four game before waving goodbye to programming in the console. But what I now notice is that when I try to update positions on the board, it just won't update it as I request. It keeps updating the same spot over and over again:
Thanks, but that's not relevant to my question here ;)
I need some kind of hint or solution as to why my "pos" function does not work properbly. There is something wrong with my 'if' statements, just don't know why or what?!
EDIT:
I know that it only works if you input 1. But I am not gonna continue wasting time on creating the rest if it's not working optimal anyways.
It should stack up when you type '1', but it doesn't. It overwrites the bottom instead.
You do not write programs in a way that requires to manually check all permutations of conditions. Let the computer do it for you. In your code the line 57 is broken. Read it carefully, and try to find a value that is NOT different from both X and Y. It would have to be equal to them both. The condition is always true.
I finnished the function for you. It got reduced to just these few lines:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
void pos(char multiArray[][7], int& value, unsignedshort& loop){
//Decide whose turn is in one check at the start
char currentPlayerMarker;
if(loop%2 == 0)
currentPlayerMarker = markerX;
else
currentPlayerMarker = markerY;
// Simplyfy condition - yours was broken - always true.
// Drop the switch, use 'value' to address the right column
// Don't case each possible variant manually - loop through them
for(int row = 5; row >=0; row--){
if(multiArray[row][value-1] == 'O'){
multiArray[row][value-1] = currentPlayerMarker;
break;
}
}
}