Question: i have a string array that contains 20 words. I made a function that take 1 random word from the array. But i want to know how can i return that word from array. Right now i am using void function, i had used char type but it wont work. Little help here ? Need to make word guessing game. 

CODE: 

```
#include <iostream>
#include <time.h>
#include <cstdlib>
#include <stdlib.h>
#include <algorithm>///lai izmantotu random shuffle funckiju
#include <string>
using namespace std;

void random(string names[]);

int main() {
     char a;
     string names[] = {"vergs", "rokas", "metrs", "zebra", "uguns", "tiesa", "bumba",
                       "kakls", "kalns", "skola", "siers", "svari", "lelle", "cimdi",
                       "saule", "parks", "svece", "diegs", "migla", "virve"};

random(names);

        cout<<"VARDU MINESANAS SPELE"<<endl;
        cin>>a;

return 0;
}

void random(string names[]){
    int randNum;
for (int i = 0; i < 20; i++) { /// makes this program iterate 20 times; giving you 20 random names.
srand( time(NULL) ); /// seed for the random number generator.
randNum = rand() % 20 + 1; /// gets a random number between 1, and 20.
names[i] = names[randNum];
}
//for (int i = 0; i < 1; i++) {
//cout << names[i] << endl; /// outputs one name.
//}

}

```

Answer: 
Make `random` return `string`. You also only need to seed the number generator once. Since you only want to get 1 random word from the array, you don't need a `for` loop.

```
string random(string names[]){
    int randNum = 0;
    randNum = rand() % 20 + 1;
    return names[randNum];
}

```

Then, in the `main` function, assign a `string` variable to the return value of the `random` function.

```
int main() {
    srand( time(NULL) ); // seed number generator once
    char a;
    string names[] = {"vergs", "rokas", "metrs", "zebra", "uguns", "tiesa", "bumba",
                       "kakls", "kalns", "skola", "siers", "svari", "lelle", "cimdi",
                       "saule", "parks", "svece", "diegs", "migla", "virve"};

    string randomWord = random(names);

    cout<<"VARDU MINESANAS SPELE"<<endl;
    cin>>a;

    return 0;
}

```
I'm not super familiar with strings, but you should be able to just declare random() as a string function.

Ex:
string random (string names[]);