#How to pull a word from an array function

31 messages · Page 1 of 1 (latest)

delicate oxide
#

Hi, I'm new to coding and trying to make a hangman game.
I'm trying to get a word from function easywordpool with the random number I got from randomwordpick function but I couldnt manage to do it. Can someone help me please

past marshBOT
#

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.

delicate oxide
#

!howto ask

finite idolBOT
#
How to Ask A Programming Question

Anyone can ask a question in our programming channels. Following the guide Writing The Perfect Question is recommended.

What To Post

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

Where To Post

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!

#
How to Format Code on Discord

• 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

Example Input

```cpp
int main() {
    return 0;
}
```

Example Output
int main() {
    return 0;
} ```
chilly venture
#

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

delicate oxide
delicate oxide
#

can you simplify it for me pls

chilly venture
#

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

delicate oxide
#

actually I'm getting different numbers every time I run it

chilly venture
#

time will potentially return the same number

#

it's dependent on your cpu speed in this case, not good

#

in any case, srand once

delicate oxide
#

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

chilly venture
#
string easyWordPool(int index) { 
   string words[4] = ...
   return words[index];
}```
delicate oxide
#

@chilly venture Thank you so much sir

#

❤️

#

now I can continue

#

thank you again

#

god bless you

#

!solved

past marshBOT
#

Thank you and let us know if you have any more questions!

#

[SOLVED] How to pull a word from an array function

past marshBOT
#

@delicate oxide

This question thread is being automatically marked as solved.