Hi,
I'm trying to write a program that reads a list of golf scores from a text file, and then stores each golfer's score to memory.
The scores are in the text file like this:
3 4 3 2 5 (18 lines like this, where the first number is par, the others are each golfer's score)
My program reads each hole just fine but I can't figure out how to properly store each golfer's score and add them up to get a final score so that I can determine who wins.
My loop looks like this:
When I compile, I'm being told that each of the variables above "might not have been initialized." When I set them all equal to zero, I get a short set of incorrect results followed by an exception.

I'm not begging for someone to write my code for me, but I can't get my head around this little piece so I thought I'd come here for help since this is due tomorrow morning.
If you need the rest of my code, just ask.
Thanks!!
I'm trying to write a program that reads a list of golf scores from a text file, and then stores each golfer's score to memory.
The scores are in the text file like this:
3 4 3 2 5 (18 lines like this, where the first number is par, the others are each golfer's score)
My program reads each hole just fine but I can't figure out how to properly store each golfer's score and add them up to get a final score so that I can determine who wins.
My loop looks like this:
Code:
// Print each golfer's score individiually
while (holeScan.hasNext())
{
int par;
int g1score, g2score, g3score, g4score;
System.out.println("PAR : " + holeScan.next());
par = Integer.parseInt(holeScan.next());
System.out.println("Golfer1: " + holeScan.next());
g1score = g1score + Integer.parseInt(holeScan.next());
System.out.println("Golfer2: " + holeScan.next());
g2score = g2score + Integer.parseInt(holeScan.next());
System.out.println("Golfer3: " + holeScan.next());
g3score = g3score + Integer.parseInt(holeScan.next());
System.out.println("Golfer4: " + holeScan.next());
g4score = g4score + Integer.parseInt(holeScan.next());
}

I'm not begging for someone to write my code for me, but I can't get my head around this little piece so I thought I'd come here for help since this is due tomorrow morning.
If you need the rest of my code, just ask.
Thanks!!












Comment