Calling Different Variables Inside For Loop

So I'm working on a program and I want to fill up anywhere from 1-6 arrays based on the user's desire. My thought is to prompt the user for how many arrays they want to fill then call a foor loop for that many iterations. Inside the for loop I plan to have a function that prompts the user to input the data then stores it to an array. The problem I've run into is that I don't know how to get the function inside the for loop to use a different array each iteration. Is there a way in C++ to use to looping variable (i?) to determine which array to call?

For instance if the arrays were named array1[] array2[] array3[].... could I do something like function("array"i[]).

Any tips or ideas are much appreciated.

~Henry
could I do something like function("array"i[])

Not really

Your best bet would be to use a multidimensional array, which essentially is like an "array of arrays":
1
2
3
4
5
6
7
8
9
10
11
int array[5][5];
    for(int i = 0; i < 5; i++)
        for(int j = 0; j < 5; j++)
	{
	    cout << "Enter a number: ";
	    cin >> array[i][j];
	}
	
    for(int i = 0; i < 5; i++)
        for(int j = 0; j < 5; j++)
	    cout << array[i][j] << endl;
Last edited on
Hey, that's great! Can't believe I didn't think of that we just discussed them in class last week xD

Thanks a lot man,

~Henry
Topic archived. No new replies allowed.