Hello everybody. I'm trying to write program with vectors and iterators. Coordinates X and Y are entered from keyboard (as structure) and placed in vector of points. It's necessary to display coordinates with maximal X and Y. This code was compiled but not display maximal X. What should I change?
#include <iostream.h>
#include <conio.h>
#include <vector.h>
#include <math.h>
struct points {
float x, y;
};
int main()
{
using namespace std;
int i;
int max;
vector<points>pointvect; //vector declaration
points point;
cout << "Enter a dimension of vectors:\n";
cin >> i;
for (int k = 0; k <= i; k++) {
cout << "Inpurt x\n";
cin >> point.x;
cout << "Input y\n";
cin >> point.y;
}
pointvect.push_back(point); // add point to the vector
// define iterators
vector<points>::iterator itr;
vector<points>::iterator first = pointvect.begin();
vector<points>::iterator end = pointvect.end();
(first)->x = max;
for (itr = first; itr <= end; itr++) {
if ((itr)->x > max) {
cout << "Maximal X is: ", (itr)->x;
}
}
getch();
return 0;
}