//for example, what code would I use to make wordone output one of four words randomly
cout<< " Once apon a time there was a "<< wordone << " who wanted to "<
//for example, what code would I use to make wordone output one of four words randomly
cout<< " Once apon a time there was a "<< wordone << " who wanted to "<
Assign wordone
a random value beforehand. For instance,
switch(rand() % 4) {
case 0: wordone = "foo"; break;
case 1: wordone = "bar"; break;
case 2: wordone = "ni"; break;
default: wordone = "knight"; break;
}
Of course, the random number generator should be seeded (see the example on this page), and wordone
should be declared (I managed to make it work as a std::string
, but if you haven't learned that, then you can use char *
).
Put the words in an array of strings.
Then use e.g. std::uniform_int_distribution
to get a number between 0
and 3
(inclusive) as index into the array, and use that string.