Filling array with for loop and cin

Hi all,

I am not sure why the following code is not working:

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
/* This program calculates the sume of the squares
of entered data */

#include <iostream>
using namespace std;

int main()
{
    int size;
        cout << "enter size of data array: ";
        cin >> size;
    
    double data[size]; //declare array of data
    double dat;
    //fill data array
    for(int i = 0; i < size; i++){ 
                  cout << "enter data: ";
                  cin >> dat;
                  data[i] = dat;}
    //output the new data array
    cout << "data array: " << data[size] <<'\n';
  
 system("pause");

  return 0;
}


I want to see an array filled with the numbers I enter, but I just get something like 1.8808ff08 as an output.

I would appreciate some help

Thanks
That is because you have to display the array the same way you take input for it:

1
2
for (i=1; i<size; i++)
   cout<<data[i]<<" ";


Something of the sort... :)
Topic archived. No new replies allowed.