Hi everyone,
I am having trouble with my program. I should point out that I am fairly new to C++ although I have done C programming before. I have five sentences (each stored in an array of char) and I need to display ONE random word from the first sentence followed by ONE random word from the second sentence followed by ONE random word from the third sentence and so on. After each word is displayed, the user hits a key to continue and then a random word will be displayed from the next sentence. After the last sentence, I need to continue the process and go back to the first sentence and display another random word with of course the possibility of the same word to be displayed because it's completely at random.
Here is my code so far for this program:
Code:
int randword(*char);
int main (int argc, char *argv[]) {
char word;
char five[100][5]={"Mary walked along the road.\0",
"Computer are cool.\0",
"This is all about C++.\0",
"Today is a nice day.\0",
"There are tons of things to see\0"};
word = randword(five);
}
int randword(char *line) {
int i,x,z,total;
total=0;
z=strlen(line);
for(i=0;i<z;i++){
if (line+i==' ')
total++;
}
x=rand() % (total + 1);
return x;
}
I apologize if any of this is hard to understand but that is probably because I can't get it working yet. I need to figure out how to display only ONE word from the sentence at random and then go to the next sentence and display ONE word from that sentence and so on. That is the part I am having the most difficulty with.
Any help, comments or suggestions would be greatly appreciated. Thanks!