- #1
lee403
- 16
- 1
I'm wanting to take user input and store it into an array.There is a a minimum and maximum number of input but otherwise the user should be able to enter any number of integers in between. Say the max number is 10 but I only want to enter 5 numbers. I used a for loop but it only ends if the maximum number is entered. Is there a way to make it end after the user has entered the desired number of integers? Or should I use a different method? (Also I'm not sure how the code editor works)
Code:
const int MAXSIZE = 10;
int Input[MAXSIZE];
for (int i = 0; i<MAXSIZE ; i++)
{
cout << "Enter a positive integer: ";
cin >> Input[i];
if (Input[i]< 0) // terminate loop if negative number is entered
break;
}
}
Last edited by a moderator: