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 :).
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 :).
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";
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.