I am writing code for a sentence generator that takes 3 nouns, verbs, and objects and outputs all possible sentence combinations in that order.
This is the code I have and not sure if I am on the right track:
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
{
const string noun[] = {"Peole", "Boys", "Girls" };
const string verb[] = {"run", "jump", "destroy" };
const string object[] = {"cars", "stores", "tracks" };
srand(static_cast<unsigned int>(time(0)));
for (int i=0; i <27; i++);
{
string noun1 = (rand() noun[]);
string verb1 = (rand() verb[]);
string object1 = (rand() object[]);
cout <<noun1<<verb1<<object1<<"."<<endl;
}
}
You don't need to use rand() here. Instead you probably want to use nested loops.