I want to make infinite Vector of elements and make the user enter the value and stop entering by pressing Enter

Viewed 53
//C++ code .. and it is working I just want to make it infinite

#include <iostream>
#include <cmath>
#include <vector>
using namespace std;
int main(){
    vector <int> N(3); //vector
    vector <int> M(3); //vector
    for(int i=0; i<3; i++){    //for loop to enter the values of vector
        cin >> M[i] >> N[i]; 
    }
    for(int i=0; i<3; i++){
        if(N[i]<=0 || M[i]<=0){
            break;
        }
        else{
        int Min = min(N[i],M[i]);
        int l = Min;
        int Max = max(N[i],M[i]);
        cout << Min << " " ;
        do{
            cout << ++Min << " "; // This all to print the numbers between M,N
            l+=Min;
        }while(Min!=Max);
        cout << "sum =" << l << endl;
        }
    }
}

// end of the code
1 Answers

An infinite array would take up an infinite amount of memory and I suppose you don't have that?

Related