Q:

C++: Using for loop I need to take infinite values of a point using arrays. How can I take values of point [ ] until 2 points of are equal

C++: Using for loop I need to take infinite values of a point using arrays. How can I take values of point [ ] until 2 points of are equal.
This is my code:
#include<iostream>
using namespace std;
int main(){
    int a, h, points [100];
    for(a=0 ; points [a]!= points [a-1] ; a++){
        cin>>points [a];

    }
}

A:

To test if two consecutive numbers are equal, you dont need 100 elements, you need 2:
int points[2], counter = 1;

// Read in first point:
cin >> points[0];

// Read until we meet our condition:
do {
    // Read a point into the next part of the array.
    cin >> points[counter];
    // toggle counter between 0 and 1
    counter = (counter + 1) % 2;
// Check if we are done:
} while (points[0] != points[1]);

Here is a live example.

