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");
}