Trying to cout an array that user has made

So I prompted the user to choose an array size (max 100) and input values. However, when I try printing the actual array, I get some huge number. Someone suggested returning arr[i] but I couldn't get that to work either.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

const int CAPACITY = 100;

int main()
{
	double arr[CAPACITY], num;
	int size, i = 0;

	cout << "How many numbers do you want to enter? (no more than 100) " << endl;
	cin >> size;
	cout << "Enter " << size << " numbers: " << endl;

	cin >> num;
	while (i < size - 1)
	{
		arr[i] = num;
		cin >> num;
		i++;
	}
	cout << arr[i];
}
Last edited on
It looks like your loop has things the wrong way round. You should get input value to be stored from the user, THEN store than input in the array.

As for outputting it again;

1
2
3
4
for (int index = 0; index < size; index++)
{
  cout << arr[index] << '\n';
}


Topic archived. No new replies allowed.