| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
I've been working with this code for the last couple days and I can't figure out how to display a multidimensional array using a char array instead of a type int array. Below is the code that I have created. Any feedback would be greatly appreciated. Thanks
//COMPILER DIRECTIVES #include<iostream> using namespace std; //FUNCTION DEFINITIONS void inform(); void displayArray(char [], char []); int main() { //LOCAL DATA char TicTacToe [3][3] = {0, 0, 0, 0, 0, 0, 0, 0, 0}; //INITIALIZES AN ARRAY OF 3 ROWS AND 3 COLUMNS //INFORMATION FOR THE USER inform(); //DISPLAY THE ARRAY displayArray(TicTacToe) return 0; }//end int main() //FUNCTION DEFINITIONS //FUNCTION TO INFORM THE USER void inform() { cout << "This program will demonstrate the use of a multidimensional\n" << "array to create a game of Tic Tac Toe!!\n\n\n"; }//end void inform() //FUNCTION TO DISPLAY THE ARRAY OF A GAME OF TIC TAC TOE void displayArray(char A[], char B[]) { for(a = 0; a < 3; a++) { for(b = 0; b < 3; b++) cout << A[a]; cout << B[b]; cout << endl << endl; } }//end void displayArray(char A[], char B[]) |
|
#2
|
|||
|
|||
|
First of all void displayArray(char A[], char B[]) is takeing two char arrays, not a single 2 demensional char array
i think the rest of the code would look something like thigs for(size_t a=0;a<3;i++) { for(size_t b=0;a<3;i++) cout<<chararray[a][b]; cout<<endl; } |
|
#3
|
|||
|
|||
|
The code worked
Quote:
Thanks for the help. I finally got the array to display itself. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Displaying a multidimensional array for a game of Tic Tac Toe |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|