Well, now that I've calmed down a bit...
Kybo_Ren, I've been tinkering with that code you provided (thank you by the way!), and I've gotten it to work with my program - mostly...
Here the full program:
Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
const unsigned int SIZE = 50;
int main()
{
for (int counter=1; counter<20; counter++)
{
const char article[5][50] = {"The", "A", "One", "Some" "Any"};
const char noun[5][50] = {"boy", "girl", "dog", "town", "car"};
const char verb[5][50] = {"drove", "jumped", "ran", "walked", "skipped"};
const char preposition[5][50] = {"to", "from", "over", "under", "on"};
const char articlex[5][50] = { "any" "the", "a", "one", "some",};
const char nounx[5][50] = {"girl", "dog", "town", "car", "boy",};
char *sentance;
srand(time(NULL));//seed random generator
int random_selector = std::rand() % (sizeof(article) / SIZE);//num of elements
sentance = new char[SIZE];//allocate
//displays article
strcpy(sentance, article[random_selector]);
cout<<sentance<<" ";
//displays noun
strcpy(sentance, noun[random_selector]);
cout<<sentance<<" ";
//displays verb
strcpy(sentance, verb[random_selector]);
cout<<sentance<<" ";
//displays preposition
strcpy(sentance, preposition[random_selector]);
cout<<sentance<<" ";
//displays second article
strcpy(sentance, articlex[random_selector]);
cout << sentance<<" ";
//displays second noun
strcpy(sentance, nounx[random_selector]);
cout<<sentance<<"."<<endl;
delete [] sentance;//deallocate
}
system("PAUSE");
return 0;
}
As you can see, the program basically just creates random sentances, like this:
Code:
A girl jumped from a dog.
Press any key to continue . . .
Sometimes, though, it seems to print two elements from any given array, one right after another, or it may skip elements from one of the arrays altogether, like this:
Code:
SomeAny town walked under some car.
Press any key to continue . . .
Or this:
Code:
car skipped on boy.
Press any key to continue . . .
From looking at the code, I can't figure out why or how to fix it.
Another problem is that the program is supposed to print out 20 *different* random sentances. If the random function, like the one you provided, determines what sentance is created based on what time it is, then it just prints the same psuedo-random sentance 20 times. It doesn't generate 20 *different* psuedo-random sentances, which is what I want it to do.
If anyone has any more suggestions, that'd be fantastic, cuz' I just don't know how to code something like that. Thanks!