Here is mine code:
#include #define dimension 3/* main duty */int key () char board
You are watching: C++ tic tac toe array
c function multidimensional-array
improve this inquiry
edited Oct 30 "18 in ~ 6:59
13.6k66 yellow badges4848 silver badges9191 bronze title
request Oct 30 "18 in ~ 5:21
Philipp PenalberPhilipp Penalber
3322 silver badges66 bronze badges
include a comment |
1 prize 1
active oldest Votes
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<>
When you re-declare board in clear_table (e.g. Char board
Further, friend declare plank as kind char in main(), e.g.
void display_table (int board<>
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<>
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<>
Also note, you have the right to pass board together a pointer-to-array that char
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.