Results 1 to 4 of 4
- 03-09-2011, 02:38 AM #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));
- 03-09-2011, 02:49 AM #2
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
please help i gotta turn this in for hw tomorrow
- 03-09-2011, 02:51 AM #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:
The variables are all in scope throughout all the loops, so they retain their value.Java Code:playerTotal = 0; for (int count = 1...
If this were not the case, you would not be able to use
Does this solve your problem?Java Code:totalTeamAvg = teamTotal/5;
- 03-09-2011, 02:55 AM #4
Member
- Join Date
- Mar 2011
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
I/O Error: Connection reset...
By dkennelly in forum Java ServletReplies: 5Last Post: 09-17-2010, 03:12 PM -
how to reset the IDE
By kattavijay in forum NetBeansReplies: 7Last Post: 03-09-2009, 03:39 PM -
How to use reset() method in struts
By rakesh_n_mehta in forum Web FrameworksReplies: 1Last Post: 11-21-2008, 03:23 PM -
in struts reset was problem
By sureshBabu in forum Web FrameworksReplies: 1Last Post: 05-07-2008, 03:26 PM -
reset query
By dd_verni in forum JDBCReplies: 0Last Post: 11-21-2007, 03:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks