How to read infinitely many inputs?

Here, we are asking the user to enter the no. of inputs he wants. How can we skip that? Point being how can we allow user to enter as many no. as he wants without him specifying it?

Hey Divyam, you can do that but you must specify a condition when you will stop getting inputs.For eg, I will take inputs until user give input as -1.

so you can code it as

int n;
cin>>n;
while(n!= -1){
    cin>>n;
}
1 Like