Random sentence generator

Can anyone help with this program:


using namespace std;
int main()
char *article[5] = { "the", "a", "one", "some", "any" };
char *noun[5] = { "boy", "girl", "dog", "town", "car" };
char *verb[5] = { "drove", "jumped", "ran", "walked", "skipped" };
char *preposition[5] = { "to", "from", "over", "under", "on" };
char sentence[50];
char word = rand()%5;
for(int i=0;i<20;i++)
sentence = *article[word];
sentence += *noun[word];
sentence += *verb[word];
sentence += *preposition[word];
cout << sentence << endl;
system ("pause");
return 0;
Please use code tags:

You need to ask a more specific question than "can anyone help" - what do you want us to help with specifically? What is the main thing you are having trouble with?
Instead of a random sentence getting generated i get a symbol this symbol y with 2 dots above it, before i was just getting numbers until i changed the raids to char with pointers. Im not sure what exactly im doing wrong in my coding
You cannot use += to append C-style strings as you seem to assume. Try using std::strings instead of char* and this would be very close to working.
I would have used std::strings butt my instructor wants it in char
Topic archived. No new replies allowed.