C++ visual-2D array

Hi

I am asked to use a 2D array(20x4).
I have put it into a function, but now i want to read and display the function by using switch method.

Can someone help me please.
More information is needed on what exactly you are to accomplish. If you already have some code written but it doesn't do what you want, then you can post it and we can help you correct it.
Here is an example of using the switch statement.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
int answer = 0;

do
{
   std::cout << "\nSelect what you want to do:\n";
   std::cout << "Read elements of the array.......1\n";
   std::cout << "Display elements of the array....2\n";
   std::cout << "Exit the program.................0\n";
   std::cout << "\nYour choice: ";

   std::cin >> answer;


   switch ( answer )
   {
      case 1:
         // enter elements of the array
         break;
      case 2:
         // display elements of the array
         break;
      default:
         if ( answer != 0 )
         {
            std::cout << "\nError: invalid input. Try anew." << std::endl;
         }
         break;
   }
} while ( answer != 0 );
Last edited on
in the function we have to open the file and display it in a 2D array.
and in the switch statement, we have to call the function, here's some codes
hope you can help me.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
switch(choice){
		case 1: ReadRegistrations (RegP, regsize);break;
		case 2: cout << "Enter event ID: ";
				cin >> eid;
				ListAthletesByEvent (RegP, regsize, eid);
				break;
		case 3: cout << "Enter country: ";
				cin >> country;
				ListAthletesByCountry (RegP, regsize, country);
				break;
		case 4: ReadResults (arr_results [][COLUMN_SIZE], regsize); //this is where we are stuck in...the underlined bracket (]) is the syntax error
				break;
		case 5: break;
		case 6: break;
		case 7: break;
		default: cout << "incorrect choice, try again\n"; break;


is the function correct??

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void ReadResults (int arr_results[][COLUMN_SIZE], int &s)
{
	int *ptr;
	int arr_result [ROW_SIZE][COLUMN_SIZE];
	string filepath = "";
	cout << "Enter result filename: ";
	cin >> filepath;

	ifstream input;
	input.open(filepath, ios::in);

	discard_line(input);

	while(input>>ws && !input.eof())
	{
		for (int i = 0; i < 20; i++ )
		{
			for (int j = 0; j < 4; j++)
			{
				cout << arr_results[i][j];
			}
		}

	}
	
}
Last edited on
Topic archived. No new replies allowed.