# Cant figure out why average for each bowler doesn't reset to 0 after each loop

• 03-09-2011, 03:38 AM
cbeier8629
Cant figure out why average for each bowler doesn't reset to 0 after each loop
public class OneBowler
{
public static void main(String [ ] args)
{
Scanner input = new Scanner(System.in);
DecimalFormat scoreFmt = new DecimalFormat("###.00");

double score = 0.0; //enetered score
double playerTotal = 0.0; // accumulator
double playerAvg = 0.0; //Player Average
double teamTotal = 0.0; //accumulator
double totalTeamAvg= 0.0;

for(int game = 1; game<=5; game++)
{
for(int count = 1; count<=3; count++)
{

System.out.print("Enter score for game" + count + ":");
score = input.nextDouble();

playerTotal +=score;

}

playerAvg = playerTotal/3;
System.out.println("The average for bowler " + game + " is " + scoreFmt.format(playerAvg));

teamTotal += playerAvg;

}

totalTeamAvg = teamTotal/5;
System.out.println("The total team average is: " + scoreFmt.format(totalTeamAvg));
• 03-09-2011, 03:49 AM
cbeier8629
• 03-09-2011, 03:51 AM
berkeleybross
Im not sure i understand your question... Where would you expect the average to be reset?

I'm assuming you want playerTotal to be set to zero before adding the score to it. In this case, before the loop you need to put this:
Code:

```playerTotal = 0; for (int count = 1...```
The variables are all in scope throughout all the loops, so they retain their value.
If this were not the case, you would not be able to use
Code:

`totalTeamAvg = teamTotal/5;`