Help with 2d array display function

I was wondering if someone could help me, I made this simple program below to try using 2d arrays. I am using cout currently to display the information but I would like to use a display function instead but I am unsure how to do this correctly and I have been trying for an hour or so now.

Any help would be appreciated.

(the commented out portion of the code shows what the program should display when executed the spacing between the data might be a bit off due to the forum text editor)

using namespace std;

int main()
{


int m[3][3] = { {2,5,7},{2,7,9},{7,2,5} };

cout << " medal1" << " " << "medal2" << " " << "medal3" << endl;
cout << "country1 " << m[0][0] << " " << m[0][1] << " " << m[0][2] << endl;
cout << "country2 " << m[1][0] << " " << m[1][1] << " " << m[1][2] << endl;
cout << "country3 " << m[2][0] << " " << m[2][1] << " " << m[2][2] << endl;
return 0;
}
//...............................Medal1........Medal2........Medal3
//Country1................2................5................7..........
//Country2................2................7................9..........
//Country3................7................2................5..........
Last edited on
I'm not sure what you have tried to do already, but I might create a display function that takes the 2d array as a parameter.

There's a section in the tutorial here on using arrays in functions - http://www.cplusplus.com/doc/tutorial/arrays/ - scroll down to Arrays as Parameters.
Topic archived. No new replies allowed.