To allow a random user to input the points of your array :
1 2 3 4 5
for(int i(0);i<sizeof(f);++i){
cout<<"Input x and y"<<endl;
cin>>f[i].x;
cin>>f[i].y;
}
The sizeof(f) is only to get the number of cells of f[], but i suggest you to ask to the user how many cells he wants to input and then create an array of this size and fill it like :
1 2 3 4 5 6 7 8 9
int n;
cout<<"Nb values ?"<<endl;
cin>>n;
Data f[n];
for(int i(0);i<n;++i){
cout<<"Input x and y"<<endl;
cin>>f[i].x;
cin>>f[i].y;
}
EDIT : My bad keskiverto is right. You should still use a vector instead of a static array.
int n;
cin>>n;
Data f[n]; // this is not legal C++
The f has automatic storage duration. Memory for it is allocated from stack. The amount to allocate has to be known already when the executable is compiled. Alas, the compiler does not know what every user will type on every run of the program.
The C language does have support for VLA (variable lenght array), but the C++ does not. C++ Library has std::vector (which does not store data in stack).
Some C++ compilers do support VLAs for C++ as an "extension". Others don't. Use of nonstandard features is not portable.
Edit: Input can fail.
1 2 3 4 5 6 7 8
double x {};
double y {};
size_t count {};
while ( count < n && std::cin >> x >> y ) {
f[count].x = x;
f[count].y = y;
++count;
}
Here a new Data object is added only if it can be fully set and the 'count' holds the actual number of elements after the input loop.
With vector:
1 2 3 4 5 6 7
std::vector<Data> f;
f.reserve( n );
double x {};
double y {};
while ( f.size() < n && std::cin >> x >> y ) {
f.emplace_back( x, y );
}