# 1d to 2d array

• 04-23-2008
helloamuro
1d to 2d array
Hi
I'm doing a wheel of fortune program in which the player scores are accumulated and tabulated in a 1d array player_turns[]={0,0,0}. The game has three rounds, and I don't know how to print the final score and declare a winner. I figure that it must have to do with converting the 1d array to a 2d array such as results[round_num][player_num]. Could someone please help or guide me how to do this. Thanks.

Code:

```int main(int argc, char* argv[]){         char phrase[NAME_LENGTH];         char puzzle[NAME_LENGTH];         char clue[NAME_LENGTH];         int puzzle_length;         int round;                 char num_players[5];         int solved = 0;         int current_player;         int player_scores[NUM_PLAYERS] = {0, 0, 0};         int a=0;                 srand(time(0));         current_player=rand()%3+1;         printf("\n");         printf("Over 50,000 in cash and prizes just waiting to be won!\n");         printf(" Here on Wheel ... of ... Fortune!\n");         printf(" (loud drum roll and music...)\n");         printf("\n");           /* Get the number of players */         while (a< 1 || a > 3){                 printf("\nHow many players will be playing the game (1-3)? ");                 if(fgets(num_players,5,stdin)){                         sscanf(num_players, "%d", &a);                         }                 printf("\n");                 }         /* Get the puzzle */                 for(round=0; round<3; ++round){         puzzle_length = initialize_array(phrase, puzzle, clue);                 current_player = rand()% a;           while (solved == 0) {                 print_score(a, player_scores);                 solved = player_turn(current_player, player_scores, phrase, puzzle, clue, puzzle_length);                                 if (solved == 0){                                         ++current_player;                                 if (current_player == a){                                 current_player = 0;                                 }                         }                 }                         solved=0;                         current_player = rand()% a;                                }                 return(0); }```
• 04-23-2008
tabstop
Why would you need a two-dimensional array? You might want two arrays -- one for the scores for the current round, and one for the "total" scores that gets added to when someone solves a puzzle.
• 04-23-2008
master5001
Yeah 2-d arrays are my personal pet peeve, but they sometimes (and I mean very rarely) serve their purpose. In any event, a struct sounds better suited for your needs this time 'round.

Example:
Code:

```struct score {   int player   int points; };```
I was about to make it a linked list, but since we are talking about something with fixed rounds you'd just make an array of struct score objects.
• 04-23-2008
helloamuro
So would I just need to declare another array similar to player_turn have it set to 0,0,0 and have player_turn added to it after each round. I really have no clue where to start. Thanks for taking the time to read this.
• 04-23-2008
tabstop
That's pretty much how the show works (of course, except that only the winner keeps the money), so yes.
• 04-23-2008
helloamuro
Would I then have to somehow break up that array to find out who was the winner?
• 04-23-2008
master5001
Well... if anything, perhaps you could just ditch the struct, and only keep track of the players. Afterall, Wheel of Fortune is cumulative as far as winning goes. So whoever has the highest at the end of the game wins. That or stick with the structs and just add each round together. But yeah, on second thought, all you need is one array.

int points[NUMBER_OF_PLAYERS]