Hi, im just bored so was mucking around on Dev-C++ and then was wondering - how could i make it so my program said a random sentance, like if i defined loads, and it said one at random.

Could you help :).

Recommended Answers

All 3 Replies

You could make an array of strings and then randomly select one from this array using rand().
If you search for rand() on the site, you should get a lot of example programs.

Niek

Can you post some code, im a little rusty :)

string ary[] = {"string1","string2" ...}
int n = sizeof(ary) / sizeof(ary[0]); // number of strings
srand(time(0));

int x = rand() % n;
cout << ary[x] << "\n";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.