Can you please give me the code a program that shuffles random sentences/phrases? Please help. Thanks.
Can you please give me the code a program that shuffles random sentences/phrases? Please help. Thanks.
Do you know about arrays?
Do you know that array subscripts are integers?
Do you know how to generate a random number from 0 to N-1 (N being the size of the array)?
If you know some of these things, then you're well on the way to being able to at least post your OWN attempt at solving the problem.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Please give more detailed terms of reference. I have a suspicion that you do not understand the strict meaning of the word "shuffle" and you actually need something else.
Ideally, write a program, you want to make it work properly. Even if it is blank with no real content.
For example:
This pseudo-program tells 5 unique fortunes from 500.Code:// program Fortune Teller char* fortunes[500]; int main(void) { unsigned int i; for( i = 0; i < 5; ++i ) { do { unsigned int f = rand() % 500; } while( already_used(f) ); puts(fortunes[f]); } return 0; }
Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev
I want to make a word game. I want each questions to be shuffled and displayed randomly. Is it possible sir? Thanks for the code anyway.
If you can dream it, you can do it. -- Tom Fitzgerald, a Disney Imagineer (frequently misattributed to Walt Disney).
Our goals are clear, tasks are defined! Let's work, comrades! -- Nikita Khrushchev
I get the logic but i dont know the syntax. What's the command for shuffle? Please help me sir.
How about showing us a program you managed to write for yourself, so we can pitch the help at the right level.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
I have a problem posting my code. My game comes in 3 modes. Easy, average and hard. I use switch statements for it to be able to select game modes. can i used the random number generator then use the if-else to print the question according to the number generated by the system?
Thanks sir. But for example in easy mode. Can i write the code under the case 1: or i have to do it outside the switch?
That's up to you. switch and if/else can be nested within each other if needed - with care.
Why don't you try it and find out? There are certainly limitations when nesting conditionals (if, switch, etc) but it is possible. If you get it wrong, your compiler will complain bitterly. That's its job, after all. So, if the compiler complains, don't panic - you will learn a fair bit from the exercise of interpreting compiler error messages to work out what problems it is complaining about, and fixing your code.
Thanks to all your answers sir. Im almost at it but i have a little problem. In generating random numbers, i sometimes get the same results consecutively. How can i make it generate numbers without repeating the same as before?
You can:
- Check to see if the newest number generated has already been generated, and if so, redo.
- Shuffle an array of possible numbers once, then pick the next number of this array to "generate" it.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
How do you shuffle sir? What's the syntax for it?