trouble with array

I am having trouble with getting an array to work and I cant figure out why? I think that the global variables would be filled once I called the get_word functions but they don't seem to be. Any help would be awesome.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
//**** Global Variables
string theSword;
string theShint;
//***  End of Globals


void get_word()
{
    enum fields {secertWord, Def, num_field};
    const int NUM_WORDS = 15;
    const string WORDS[NUM_WORDS][num_field] =
    {
        {"axiom", "A self-evident or universally recognized truth"},
        {"logic", "The study of principles of reasoning"},
        {"control", "To exercise restraint or direction over"},
        {"reliance", "confident or trustful dependence"},
        {"diference", "an instance or point of unlikeness or dissimilarity"},
        {"point", "To indicate a position or direction"},
        {"array", "to place in proper or desired order"},
        {"vector", "a quantity possissing both magnitude and direction"},
        {"construct", "To build or form by putthing togehter parts"},
        {"function", "the purpose for which something is designed or exists"},
        {"string", "A slender cord or thing thread used for binding or tying"},
        {"enumeration", "a catalog or list"},
        {"switch", "to shift or exchange"},
        {"branch", "to divide into separate parts or subdivisions"},
        {"program", "a plan of action to accomplish a specified end"}
    };

	srand( time(NULL));
	int pick = (rand() % NUM_WORDS);
    string theSword = WORDS[pick][secertWord];
    string theShint = WORDS[pick][Def];

};


int main()
{
    get_word();
    cout<<"the secert word is"<<theSword<<"and the hint is :"<<theShint<<"\n";
    stop();
    return 0;
}


Looks like this a problem with understanding the scope of a variable. to make it work the way I thought it would I declared the array as global and turned the random number call into a function returning a random number.
I found the problem...,i.e.,.In line 33 & 34 you dont have to declare new strings.........this makes them of local scope.........

In real you are creating two more strings of local scope and storing values in them...........

correct statement would be

theSword = WORDS[pick][secertWord];
theShint = WORDS[pick][Def];
Your right it works that way too! I wish I would have tried that first would have saved so much typing. Thanks for lesson. As a result, I learned that if I use a global and cast its type in function it changes its scope!
As a result, I learned that if I use a global and cast its type in function it changes its scope!

Um, no. Lines 33 and 34 aren't casting anything. They are declarations of new, local variables.
Topic archived. No new replies allowed.