Use a while loop.
syntax:
Code:
while(condition is true)
{
//do what's in here
}
The condition can be any expression such as (i < 4) or ( i == 3 )
To do loop again if the user did something wrong, then use the
continue statement. This will jump back up to the beginning
of the loop.
You could also us a do...while() loop which will execute at least
once.
syntax:
Code:
do
{
//do what's in here
}while(condition is true); //note the semi-colon
Here's an example:
Code:
int i = 0;
int array[6] = {1,2,3,4,5,-1};
while( array[i] != -1)
{
cout << array[i] << " ";
}
As for validation, you'd have to read the input into a string, then
test the characters of the string to see that the input was valid.
BUT
cin will accept anything so if the user enter a number then some
characters, then cin will ignore the charcters.