Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,262 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,506 people online right now. Registration is fast and FREE... Join Now!




Need help to access a random word from a list of words!

 
Reply to this topicStart new topic

Need help to access a random word from a list of words!

nickyp
6 Nov, 2006 - 11:18 AM
Post #1

New D.I.C Head
*

Joined: 6 Nov, 2006
Posts: 1


My Contributions
Hey, im making a slot machine program and I need help. Im not looking for any code since i want to learn it myself. But I do need some help to find out what method I should use. I was thinking i should create a list of words(like lemon, strawberry, and orange, and bar) and somehow assign them to a number, which I would make a program to randomly generate a number and output the associated word. What kind of method should I use to make this happen.
User is offlineProfile CardPM
+Quote Post

Amadeus
RE: Need Help To Access A Random Word From A List Of Words!
6 Nov, 2006 - 11:34 AM
Post #2

g++ -o drink whiskey.cpp
Group Icon

Joined: 12 Jul, 2002
Posts: 12,230



Thanked: 40 times
Dream Kudos: 25
My Contributions
I would create an array of strings objects that contains all your words, then use the rand() function to generate a number between 0 and the array length minus 1. Then output that element of the array.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:12PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month