# Thread: Storing game scores for 2 teams in a 2D array

1. ## Storing game scores for 2 teams in a 2D array

Let me start by saying I am new to this forum and new to C programming. I am struggling with the concept of storing 2 teams scores in a 2 d array from a menu based system. Yes, this is a homework assignment, and I am not asking anyone to write the assignment for me. I just would like to understand why my code is not placing values as I would expect them to. I am here to learn, I am taking the project one piece at a time. The menu functions and does work, the next step was placing elements in the array. This does not work sadly. Thank you in advance.

Code:
```/
//  main.c
//  game_scores
//
//  Created by on 1/24/19.
//

#include <stdio.h>
#include <stdlib.h>

#define score 100
#define teams 2

// declare functions

void game_result(void);
void list_scores(void);
void games_won(void);
void scores_sort(void);

// declare variables

int game[score] [teams] , j = 0, i = 0;
char choice;

int main()

{

return 0;
}

{

do
{
printf("\n\n************************* \n");
printf("************************* \n\n");
printf("[A]Enter game result \n");
printf("[B]Current Record(# of wins and # of losses and # of ties \n");
printf("[C]Display ALL results from all games WON \n");
printf("[D]Display ALL results ordered by oponent score from low to high. \n");
printf("[E]Quit the program \n");
printf("Enter an option:");
scanf(" %c",&choice);

switch(choice)
{
case 'A': game_result();
break;
case 'B': list_scores();
break;
case 'C': games_won();
break;
case 'D': scores_sort();
break;
case 'E': printf("Quitting program!\n");
exit(0);
break;
default: printf("Invalid choice!\n");
break;
}

} while (choice != 'E');

}

// begin function items
//*********************

// loop through game score values

void game_result(void)
{

for(i=0; i<score; i++)
for(j=0;j<teams;j++)
game [i][j] = 0;
printf("Enter game scores:");
scanf("%d", &game[i][j]);

return;
}

// list game scores in array

void list_scores(void)
{

return;
}

// sort the by games won

void games_won(void)
{

return;
}

// sort score values

void scores_sort(void)
{

return;
}```

2. Code:
```    for(i=0; i<score; i++)
for(j=0;j<teams;j++)
game [i][j] = 0;
printf("Enter game scores:");
scanf("%d", &game[i][j]);```
Well C isn't Python, where indentation alone specifies block scope.
In C, you have to use braces to make your intention explicit.

3. Funny you should reference Python, that is the other class I am taking.

So then it should look something like this? After testing this and using my debugger I can see it is populating the array now, but it continues to ask for input rather than just populating one row of values. Instead, it populates a row and then moves to the next row and populates and so on. Would I move my return up to the inner nest?

Code:
```for(i=0; i<score; i++){
for(j=0;j<teams;j++){
game [i][j] = 0;
printf("Enter game scores:");
scanf("%d", &game[i][j]);
}
}
```

4. Please accept my thanks, your reply got me thinking and I believe I have found a better way to obtain the desired result. I decided to ask the user for the number of games and teams. and pass those variables to define my loops and my array. This way the expectation is set, the user will know how many values they will need to enter.

Thank you again.