Do you need to keep the array in order? If you don't then you could just loop through the array, each time picking a random name in the array and swapping it with the current name. If you do need to keep the array in order you could just create a new array for the randomized names.
what your for loop is doing now is for each iteration, it assigns a random name to Random, prints it, then writes that random name back into the array, overwriting whatever the current name was.
Assuming you don't need to keep the array in order you could...
sir can i ask a question again??
sir how can i group the names of my program into three group and that is will randomize.. pls help me sir..according to my teacher we will use the two dimentional arrays,
i dont know how to use the 2D arrays.. tnx sir..
this is the sample of the out of the program..
the name in order:
budz
konan
nagato
itachi
tobi
madara
naruto
danzou
kakashi
You can think of this 2D array as a set of 10 char arrays that can hold up to 50 chars, in other words it can hold up to 10 names that are less 50 characters long.
to print out the names from this array in a loop all you need to do is loop through the first subscript ( [ 10 ] )...
1 2 3 4
for( int i = 0; i < 10; i++ )
{
cout << names[ i ] << " " << endl;
}
If you want to group your random names into threes, all you need is a counter that counts the number of iterations through the loop, when it gets to 3 output and extra "endl" and set the counter back to 0;
1 2 3 4 5 6 7 8 9 10 11 12
int counter = 0;
for( int i = 0; i < 10; i++ )
{
++counter;
cout << names[ i ] << " " << endl;
if( counter == 3 )
{
cout << endl;
counter = 0;
}
}