In my code I have actually a total of ten functions and also I was just able to totally code two of them and i have my main function all set up. The other features I am totally lost on. It would be a substantial help if girlfriend can add example coding and also explanations for this reason I might get a much better understanding.

Here is mine code:

#include #define dimension 3/* main duty */int key () char board; int row, col; clear_table (board); display_table (board); execute get_player1_mover (board, row, col); generate_player2_move (board, row, col); while (check_end_of_game (board) == false); print_winner (board); return 0;/* display table duty */void display_table (int board<>, int SIZE){ int row, col; printf ("The present state that the video game is:\n"); for (row = 0; heat The functions I"ve completed space display_table and the clear_table and also I almost completed get_player1_move but I am stuck with exactly how to make sure it prints out table.

You are watching: C++ tic tac toe array


c function multidimensional-array
share
improve this inquiry
monitor
edited Oct 30 "18 in ~ 6:59
*

mrundal
13.6k66 yellow badges4848 silver badges9191 bronze title
request Oct 30 "18 in ~ 5:21
*

Philipp PenalberPhilipp Penalber
3322 silver badges66 bronze badges
1
include a comment |

1 prize 1


active oldest Votes
1
It is apparent you room stuck on expertise your function declarations and also where you have actually used int and also where you have actually used char. (types matter).

Before addressing anything else, the No. 1 thing you can do to let her compiler help you password is to enable compiler warnings. That way at minimum for gcc/clang, include -Wall -Wextra together compiler choices (recommend: -Wall -Wextra -pedantic -Wshadow), because that VS (cl.exe) usage /W3 and also -- do not accept code till it compiles cleanly without warning! her compiler will tell girlfriend the specific line (and plenty of times the column) wherein it sees problem code. Permit the compiler aid you write much better code.

Next, you usage the continuous SIZE to administer the size for your board. Good! If you require a consistent -- #define one or an ext -- together you have. Understand, as soon as you define a constant, that has paper scope, it have the right to be seen and also used within any function within that document (or in ~ any record that includes the header in i m sorry the continuous is defined). Together such, over there is no must pass size as a parameter to your functions. They recognize what size is, e.g.:

void display_table (char board<>);void clear_table (char board<>);Next, you cannot re-declare char board; as you have in clear_table(). That declaration "shadows" the explanation of plank from main() the you happen a parameter, e.g. Void clear_table (char board<>);. (thus the advice of consisting of the -Wshadow compiler choice to warn you once you try something the creative....) The same applied to display_table.

When you re-declare board in clear_table (e.g. Char board;) and also then usage board in clear_table, you are updating the re-declared board the is local to the duty (and is thus damaged when the function returns), therefore the alters are never ever seen back in main().

Further, friend declare plank as kind char in main(), e.g.

char board = 0; /* initialize all variables */but then attempt to happen board as kind int, e.g.

void display_table (int board<>, int SIZE) {Your parameter needs to match your declaration type.

With those an easy adjustments and cleaning up her clear_table and also display_table simply a tad, you could do other like:

/* display table duty */void display_table (char board<>){ int row, col; printf ("\nThe existing state of the game is:\n"); because that (row = 0; heat Now simply make sure you carry out a prototype the the features above main() in your record so main() knows of the existence of both functions before they are referred to as in main() (alternatively, you might just move the definition the both functions above main()). (a function must it is in declared before it deserve to be provided -- that means above the role where that is referred to as in a "top under read" of the file)

Your password for both attributes wasn"t that far off, you to be just absent a few implementation details (rules). To provide a working clear_table and display_table (along with a cheezy diagonal_x duty to initialize the diagonal line to every "x" and also the remainder to "o", you might do:

#include #define dimension 3 /* if you require a constant, #define one (Good!) */void display_table (char board<>);void clear_table (char board<>);/* cheezy init funciton */void diagonal_x (char (*board)){ for (int row = 0; row (note: whether you include enclosing "" and "" ~ above loops or conditionals with only a single expression is as much as you. It may assist keep things directly for girlfriend -- approximately you)

Also note, you have the right to pass board together a pointer-to-array that char , e.g. Char (*board) and char board<>, they room equivalent.

Example Use/Output

Note: I added a room before every character in the plank to make the display a little much more readable -- you deserve to remove that if friend like.

See more: Stardew Valley Give The Sand Dragon His Last Meal, Give The Sand Dragon His Final Meal

$ ./bin/checkerinitThe current state of the video game is: _ _ _ _ _ _ _ _ _The present state of the game is: x o o o x o o o xThis should acquire your going. Allow me know if girlfriend have additional questions.