# minimum numbers to be entered into an array

• 04-05-2003
volk
minimum numbers to be entered into an array
Is it possible to accept a minimum of ten numbers to be entered into an array? I know it's possible to accept a maximum of ten numbers to be entered into an array.

Is this where vectors come in?
• 04-05-2003
RoD
dont let the loop leave until ten are taken

Code:

```int somearray[10]; for (int i = 0; i < 10; i++) { cout << "Enter int: "; cin >> somearray[i]; }```
• 04-05-2003
volk
Quote:

Originally posted by RoD
dont let the loop leave until ten are taken

Code:

```int somearray[10]; for (int i = 0; i < 10; i++) { cout << "Enter int: "; cin >> somearray[i]; }```

That code doesn't look like it scans for a minimum of ten numbers; it looks like it's scanning for exactly ten numbers. What if I want to enter eleven numbers?

I guess what I want is impossible to do with arrays...
• 04-05-2003
Magos
Code:

```for(int i=0; i<10; i++) {   cin >> Array[i]; } int Temp; int j = 10; do {   cin >> temp;   if(Temp != -1)   {       Array[j] = Temp;       j++;   } }while(Temp != -1)```
Assuming that the exit condition is the user enters -1.

EDIT:

Or even better:
Code:

```int Temp; int i = 0; do {   cin >> Temp;   if(Temp != -1)   {       Array[i] = Temp;       i++;   } }while((Temp != -1) || (i < 10))```
• 04-05-2003
alpha
well, if you want to change the size, vectors come into play. you can use resize() if you need to.

or you could also use a linked list and dynamically allocate memory.