Hey. I'm having a little problem. Im almost done with my tic tac toe . Just when checking at last who won ..I had to write around 12 if-statements . I was wondering if there was an easier method to it... !
There are easier ways of doing this, using a 2d array, using numbers (such as the numpad) to represent grid positions for user entry, and the use of ternary operators to check for victories. When I learned about the ternary operators (sometimes referred to as conditional operators) I was able to reduce the number of if/else statements involved significantly. An example would be something like: win=((array[0][0)==1 && array[0][1]==1 && array[0][2]==1) ? 1 : win);
This translates roughly to "If array[0][0],array[0][1], and array[0][2] all equal 1, then win does too, otherwise it is equal to itself and nothing changes."
BTW, you can greatly increase the readability of your code examples using code tags. You can use them easily by clicking the "<>" button and putting your code between the generated code tags, so you don't have to type "[clode] or [/clode]". (Deliberately misspelled so they would show up, it is supposed to be "code".)