![]() |
basic C++ question:
So I have this 2 dimensional Array (3X3)
and I want to make it so "if there is an "X" in slot 2-2, return a "YES" tried doing if ( board[2][2] hahahaha 'X' ) { cout << "Yes"; } else { cout << "No"; } and I keep on getting "No"s at every turn can anybody help me out on this one? what I am actually trying to do, is that it's a TIC TAC TOE game, and I need to stop the program once someone wins... help me out yooo!!! 178340550 |
ah shit.. haven't done any C++ in over 10years
damn.. now I wanna know too and I know it's a fuckin simple thing :disgust |
post the code somewhere where it wont go hahahaha
|
Quote:
|
Quote:
Try this: Code:
if(board[1][1]hahahaha'X') { // Is there an X in the middle square? |
A 'win' state checker:
Code:
char *checkwin(char board[2][2]) // Prototype might be a bit off, adjust accordingly ;) |
Quote:
Doing a assignment for cs class? |
use the min max algo, i coded a tic tac toe game for school a couple years ago using this algo, and it was undefeatable..
http://personal.vsnl.com/erwin/tictactoe.htm |
array element numbering starts with 0 not 1
|
Nerds :error
just kidding :pimp |
Nerds :error
:1orglaugh |
got it! thanx guys
now another question, how do I reset an array? make it all empty again? |
Damn! I used to know C++, now I don't remember shit!
|
Quote:
Code:
memset((void *)array_ptr, number_of_elements * sizeof(array_type), 0);Code:
array_ptr = (array_type *)calloc(number_of_elements, sizeof(array_type));HTH. HAND. :thumbsup PS - If you malloc()'d the array originally, make sure you free() it before doing a new malloc(), otherwise you'll leak ram. :2 cents: |
everything works!!! thanx alot for your help guys
|
| All times are GMT -7. The time now is 06:50 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2026, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123