# disc golf program troubles

• 09-25-2012
Incompetence
disc golf program troubles
Hey!

I was trying to write a simple program to tally each players score in a game of disc golf, then display it at the end. Maybe there's a better approach I could use?

Anyways, I keep getting junk numbers for the sums array. I set up an array for the amount of players, and the score per hole. I'm trying to add the holes to get a total, but I'm getting back junk. Help would be very much appreciated!

Thank you!

Here's the code

Code:

```#include <stdio.h> #include <stdlib.h> main(){         int holes[18];     int players = 0;     int i, i2;     int h, g, f = 0;     int x = 1;     int sum = 0;     int sums[players];     sums[1] = 0;         printf("You played a round of disc golf\nLet me add up the scores for you!\n");     printf("Please enter the number of players: \n");     scanf("%d", &players);     for (i = 1; i <= players; ++i){     printf("Enter the scores for player %d\n", x++);             for (i2 = 0; i2 < 18; ++i2){         scanf("%d", &holes[i2]);         printf("%d\n", holes[i2]);}         }             for (g = 0; g < players; ++g){         ++f;         for (h = 0; h < 18; ++h){           printf ("%d\n", holes[h]); // trying to find where it goes wrong           printf ("%d\n", sums[f]);           system("PAUSE");           sums[f] += holes[h];           printf ("%d\n", holes[h]);           printf ("%d\n", sums[h]);           system("PAUSE");           }                     }                                             printf("this is %d", holes[5]);                    for (i = 0; i < players; ++i)       printf("\nplayer %d's score is %d\n", i + 1, sums[i]);             system("PAUSE"); }```
• 09-25-2012
Click_here
Code:

```int players = 0; ... int sums[players];```
Your problem would be with sums[]
• 09-25-2012
Incompetence
Quote:

Originally Posted by Click_here
Code:

```int players = 0; ... int sums[players];```
Your problem would be with sums[]

Okay, I tried to just initialize it after players gets input

Code:

```scanf("%d", &players); int sums[players];```
But that still gave me junk. Any ideas for a work around?
• 09-25-2012
Click_here
Show your new code in full
• 09-26-2012
qny
Initialize the elements of the array

Code:

```    int sum[players];     for (int k = 0; k < players; k++) sum[k] = 0;```