#How to pull a word from an array function
31 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
!howto ask
Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.
State your problem clearly and provide all necessary details:
• the relevant portion of your code, or all of it
• the expected output
• the actual output (or the full error)
🏆 Gold Standard: Minimal Reproducible Example
Provide the relevant code in the message, and format it nicely with a code block*. If it's too much for one message, you can upload it:
• Compiler Explorer for most C/C++ snippets
• OnlineGDB for interaction, debugging
⛔ Do not post screenshots, let alone photos of your screen!
• type three "backticks" (not quotes/apostrophes, on QWERTY layout, left of 1-key)
• on the same line, type the file extension for that language (c or cpp)
• enter your code on a new line and put another three backticks at the end
```cpp
int main() {
return 0;
}
```
int main() {
return 0;
} ```
srand is seed-rand, you only call it once
i.e. pull it out of your top function
your easyWordPool can take an int parameter and return the proper element
your word is 5 strings long but only 4 elements defined that's not good, and your randomNumber should be 0-3 not 1-4, c++ is zero indexed
yeah I realised that solved it. thank you
my english isnt that very well
can you simplify it for me pls
move the srand... call into main()
otherwise this is called right before your rand(), which makes it have the same value every time
since you're resetting the seed
actually I'm getting different numbers every time I run it
time will potentially return the same number
it's dependent on your cpu speed in this case, not good
in any case, srand once
thank you,
so how can I return a word from my array function based on the number I got from rand()
I've tried a few things but couldnt do it
string easyWordPool(int index) {
string words[4] = ...
return words[index];
}```
@chilly venture Thank you so much sir
❤️
now I can continue
thank you again
god bless you
!solved
Thank you and let us know if you have any more questions!
[SOLVED] How to pull a word from an array function
@delicate oxide
This question thread is being automatically marked as solved.