   Tic Tac Toe
  hey,This is the first game ive made in C++ im still in Middle School so im not sure how itll be, so far there are no graphics and all its just text, but I want to make sure that my code works before i implement the graphics. So could you guys just run it and make sure that the win and draw things are working and that ther are no combinations that arent working. (Dont look at the main() code I know its shit but its just temporary until I get graphics). Could you just compile the code and run it? (I made it in Turbo C++, so if you get any errors in DevC++ could you fix them? ) Thanx alot.#include&lt;iostream.h&gt;#include&lt;conio.h&gt;int norepeat(int[5], int[5], int, int);void sort();int check(int[5], int[5], int);int draw(int[5], int[5]);int x[5] = { 10, 10, 10, 10, 10 };int o[5] = { 10, 10, 10, 10, 10 };int main(){int choicex, choiceo;int turn = 0;int rep = 0;int turn1 = 0;int draw1 = 0;while (rep == 0 && draw1 == 0) {choose:cout &lt;&lt; endl &lt;&lt; "X chooses: ";cin &gt;&gt; choicex;int b = norepeat(x, o, choicex, turn);if (b == 0){goto choose;}x[turn] = choicex;++turn;sort();rep = check(x, o, turn);draw1 = draw(x, o);if (rep != 0 || draw1 != 0){goto end;}choose1:cout &lt;&lt; endl &lt;&lt; "O chooses: ";cin &gt;&gt; choiceo;b = norepeat(x, o, choiceo, turn1);if (b == 0){goto choose1;}o[turn1] = choiceo;++turn1;sort();rep = check(x, o, turn1);draw1 = draw(x, o);end:}getch();return 0;}void sort(){int temp;for (int sort1 = 0; sort1 &lt; 4; sort1++){for (int sort2 = sort1 + 1; sort2 &lt; 5; sort2++){if (x[sort1] &gt; x[sort2]){temp = x[sort2];x[sort2] = x[sort1];x[sort1] = temp;}if (o[sort1] &gt; o[sort2]){temp = o[sort2];o[sort2] = o[sort1];o[sort1] = temp;}}}}int norepeat(int x[5], int o[5], int choice, int turn){int norepeat = 1;if (choice &gt; 0 && choice &lt; 10){for (int repeat = 0; repeat &lt; turn + 1; repeat++){if ( x[repeat] == choice || o[repeat] == choice){norepeat = 0;}}}else{norepeat = 0;}return norepeat;}int check (int x[5], int o[5], int turn){int check = 0;for (int z = 0; z &lt; 5; z++){for (int j = 0; j &lt; turn - 2; j++){for (int i = j + 1; i &lt; turn - 1; i++){for (int k = i + 1; k &lt; turn; k++){if( x == x[j] + z && x[k] == x + z){if ( ( x[j] &gt; 0 && x[j] &lt; 4 ) || x[j] == 4 || x[j] == 7 ){if ( x[j] != 3 && z == 2 && x[k] != 7 ){check = 0;cout &lt;&lt; endl &lt;&lt; "Cond 2";return check;}if ( (x[j] != 1 || x[j] != 4 || x[j] != 7) && z == 1){check = 0;cout &lt;&lt; endl &lt;&lt; "Cond 4";}else{check = 1;cout &lt;&lt; endl &lt;&lt; "Cond 1 X Wins";return check;}}if ( (x[j] == 1 || x[j] == 4 || x[j] == 7) && z == 1){check = 1;cout &lt;&lt; endl &lt;&lt; "Cond 5 X wins";}if ( x[j] == 3 && z == 2 && x[k] == 7){check = 1;cout &lt;&lt; endl &lt;&lt; "Cond 3 X wins";}return check;}if( o == o[j] + z && o[k] == o + z){if ( ( o[j] &gt; 0 && o[j] &lt; 4 ) || o[j] == 4 || o[j] == 7 ){if ( o[j] != 3 && z == 2 && o[k] != 7 ){check = 0;cout &lt;&lt; endl &lt;&lt; "Cond 2";return check;}if ( (o[j] != 1 || o[j] != 4 || o[j] != 7) && z == 1){check = 0;cout &lt;&lt; endl &lt;&lt; "Cond 4";}else{check = 2;cout &lt;&lt; endl &lt;&lt; "Cond 1 O Wins";return check;}}if ( (o[j] == 1 || o[j] == 4 || o[j] == 7) && z == 1){check = 2;cout &lt;&lt; endl &lt;&lt; "Cond 5 O wins";}if ( o[j] == 3 && z == 2 && o[k] == 7){check = 2;cout &lt;&lt; endl &lt;&lt; "Cond 3 O Wins ";}return check;}}}}}return check;}int draw (int x[5], int o[5]){int check = 0;int draw = 0;for (int l = 0; l &lt; 5; l++){check = check + x[l] + o[l];if ( check == 55 && l == 4){draw = 1;cout &lt;&lt; endl &lt;&lt; "Its a Draw" &lt;&lt; endl;return draw;}}return draw;}EDIT: Large blocks of code should be wrapped in 'source' tags...   
  sorry about no indents, its not letting me do them   ;Quote:Original post by General Zaydsorry about no indents, its not letting me do themYou need to use [source]...[/source] tags to get proper text formatting. I've edited your post for you.Also, I'm going to push this over to 'For Beginners' - Maybe someone there will be so kind as to offer you a code review. I can't really see any reason why this landed in DirectX [smile].Cheers,Jack   ;  There were a few things that I really didn't like about your code.  Your use of goto(not really needed) and the fact you didn't use a game board in your code.  It was very hard to figure out how your code worked without comments as well, so I decided to just write my own tic-tac-toe game to offer some measure of inspiration.This code isn't nearly the best, just something quick and dirty I wrote up to better show how you might organize your code.  It makes use of vectors for the board, and strings for anything input related.  If you want to know how things like vector, string, getline, etc works, just do a search for something like "vector c++ tutorial" and you'll likely get a good result.// Two player tic-tac-toe, written by Dan J.#include<iostream>#include<vector>#include<string>using std::string;using std::cout;using std::vector;using std::endl;using std::cin;string get_user_name();string get_symbol(string user_name);void print_board(vector<char> board);void main_game(string player_name[2]);bool valid_position(int position, vector<char> board);bool check_for_win(vector<char> board);int main(){// who is playingstring player_name[2];// Title screencout << "Welcome to tic-tac-toe!" << endl;// get user names:player_name[0] = get_user_name();player_name[1] = get_user_name();// continue playing until users want to quitstring user_choice;do{main_game(player_name);cout << "Do you wish to (q)uit? ";cin.ignore(80, '\n');getline(cin, user_choice);}while(user_choice != "q" && user_choice != "Q");return 0;}string get_user_name() {cout << "Enter player name: ";string player;getline(cin, player);return player;}void print_board(vector<char> board){assert(board.size() == 9);cout << board[0] << " | " << board[1] << " | " << board[2] << endl;cout << "---------" << endl;cout << board[3] << " | " << board[4] << " | " << board[5] << endl;cout << "---------" << endl;cout << board[6] << " | " << board[7] << " | " << board[8] << endl << endl;}void main_game(string player_name[2]){// the default board the users start playing on// only used to initialize the vectorchar def_board[9] = {'1', '2', '3', '4', '5', '6', '7', '8', '9' };// initialize playing boardvector<char> board(def_board, def_board + 9);int turn = 0; // first player is X, second Odo {print_board(board);cout << player_name[turn] << ", enter the number where you wish to move: ";int position;cin >> position;position--;if(!valid_position(position, board)){cout << "I'm sorry, you can't move there." << endl;continue;}// mark the position on the boardif(turn == 0){board[position] = 'X';}else{board[position] = 'O';}// check for if the last move wonif(check_for_win(board)){cout << "Congratulations, " << player_name[turn] << ", you won!" << endl;return;}turn = (turn + 1) % 2;}while(true);}bool valid_position(int position, vector<char> board){if(position < 0 || position > 8){return false;}if(board[position] == 'X'){return false;}if(board[position] == 'O'){return false;}return true;}bool check_for_win(vector<char> board){// there are 8 possible ways to win.// Three horizontalif(board[0] == board[1] && board[1] == board[2]){return true;}if(board[3] == board[4] && board[4] == board[5]){return true;}if(board[6] == board[7] && board[7] == board[8]){return true;}// Three verticleif(board[0] == board[3] && board[3] == board[6]){return true;}if(board[1] == board[4] && board[4] == board[7]){return true;}if(board[2] == board[5] && board[5] == board[8]){return true;}// Two diagonalif(board[0] == board[4] && board[4] == board[8]){return true;}if(board[2] == board[4] && board[4] == board[6]){return true;}// otherwise no one wonreturn false;}This was written in Code::Blocks, with the mingw compiler.   ;  Thank you for taking the time to write out a whole program :). I was looking at your comments and the gotos in the main function were only temporary until I implemented a whole graphics interface (which I am working on right now). Basically my program initializes all 9 squares to values in a array by the users input. I then derived an alogorithm of possible wins by tic tac toe and my program checks that if the values of the arrays fit into the equation  through the use of for loops nd ifs. ;  So having goto's is an excuse for not using graphics? Wonder how all the textbased rpg's would look like :-)   ;  Yeah it is do you pay any attention to what I was writing (textbased is only temp.)   