2
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by Ancient Dragon
0

Lets say you have 5 strings, you need to generate a randome number between 0 and (but not including) 5. Use the mod operator % to accomplish that int num = rand() % 5;

0

right but I am not using int i am using an array. So what would the systax be

char array1[j] = rand () % i;

???

0

I have a couple of sentences in an array. I need to randomly display 1 of them. How can I do this?

So what would the systax be

char array1[j] = rand () % i;

???

no it is not like that. you do not set the elements of the array to be a number from 0-5, what you want is just to display the string as you said in your original post cout << array[rand() % 5] << "\n"; Note in the above the value 5 assumes you have 5 strings. Replace that with however many strings you actually have in your array.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.