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?
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?
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?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]; }
I guess what I want is impossible to do with arrays...
Assuming that the exit condition is the user enters -1.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)
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))
Last edited by Magos; 04-05-2003 at 05:29 PM.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
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.