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

1. Member
Join Date
Mar 2011
Posts
3
Rep Power
0

## 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));

2. Member
Join Date
Mar 2011
Posts
3
Rep Power
0
please help i gotta turn this in for hw tomorrow

3. 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:
Java 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
Java Code:
`totalTeamAvg = teamTotal/5;`
Does this solve your problem?

4. Member
Join Date
Mar 2011
Posts
3
Rep Power
0
sorry for the confusing question butyes that worked! i thought that wouldnt make a difference cause i originally initialized playerTotal to 0.0 in the beginning. but thanks!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•