Random Coordnate generator
Jan 22, 2009 at 4:02pm Jan 22, 2009 at 4:02pm UTC
In my Highschool Programming club we are trying to make a guessing game that works similar to Battleship, guess the cordinates that the Computer randomly generators I think I have found an example that I could use in order to do this but it conufuses me at this point,
1 2 3 4
char State[50][255] = {"Alabama" ,
"Alaska" ,
"Arizona" ,
"Arkansas" ,
Etc.
Im assuming the 50 after char State means the fifty states that it will pick from, whats the 255 mean?
Jan 22, 2009 at 4:52pm Jan 22, 2009 at 4:52pm UTC
That is the length of the 2nd dimension in the char table you have declared, i.e. the maximum length of any state's name.
Jan 23, 2009 at 12:26pm Jan 23, 2009 at 12:26pm UTC
Thanks, thats one thing I thought but wasnt sure.
Jan 25, 2009 at 7:34pm Jan 25, 2009 at 7:34pm UTC
Why not use a C++ data structure instead of a 2D character array?
A fixed length vector of strings, or an array of strings would be a better idea.
e.g
1 2 3 4 5 6
string State[50] = {"Ala" , "Bala" etc};
vector<string> States;
States.resize(50);
States[0] = "Alabama" ;
Topic archived. No new replies allowed.