I am having trouble with this little piece of code:
The error that I'm getting is this : "invalid initializer" on line 13.
Can somebody tell me what I'm doing wrong and where the problem is??
I'm sorry if it's really obvious but I'm new to C++.
Thanks in advance
Code:
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
string getword(string wordlist[]);
int main() {
string wordlist[] = {"robbery", "soccer", "antibiotics"};
char word[20] = getword(wordlist);
cout << word << endl;
system("PAUSE");
return 0;}
string getword(string wordlist[]){
srand((unsigned)time(0));
int num = rand()%3; // needs to be length of list
string word;
word = wordlist[num];
return word;}
Can somebody tell me what I'm doing wrong and where the problem is??
I'm sorry if it's really obvious but I'm new to C++.
Thanks in advance
Comment