Saving multiple inputs into array

Hello all who read, I think it goes without saying that I am new to C++. The code below is a smaller part of something I am working on but need to fix this before I can move on.

I need to save the multiple user inputs into my array, then when using
cout << myArray[size] << endl; , have it output whatever numbers the user has inputted. So far, I have it to where it just outputs whatever the last input the user gives, not all of them. Any help would be appreciated, and thanks for your time.

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
#include <iostream>
using namespace std;

int main(){

int size, j, i;

	cout << "Input array size" << endl;
	cin >> size;

	int myArray[size];

	for(j=0; j<size; ++j){

		cout << "Input variable" << endl;
		cin >> myArray[size];

		
}

	cout << myArray[size] << endl;
	
	return 0;

}
you need to access each array element to write some data there.
1
2
3
4
5
6
for(j=0; j<size; ++j){

		cout << "Input variable" << endl;
		cin >> myArray[j];
}
and
cout should be in in loop to;

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