Results 1 to 4 of 4
  1. #1
    cbeier8629 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default 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. #2
    cbeier8629 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    please help i gotta turn this in for hw tomorrow

  3. #3
    berkeleybross's Avatar
    berkeleybross is offline Senior Member
    Join Date
    Feb 2010
    Location
    England
    Posts
    187
    Rep Power
    5

    Default

    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. #4
    cbeier8629 is offline Member
    Join Date
    Mar 2011
    Posts
    3
    Rep Power
    0

    Default

    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!

Similar Threads

  1. I/O Error: Connection reset...
    By dkennelly in forum Java Servlet
    Replies: 5
    Last Post: 09-17-2010, 04:12 PM
  2. how to reset the IDE
    By kattavijay in forum NetBeans
    Replies: 7
    Last Post: 03-09-2009, 04:39 PM
  3. How to use reset() method in struts
    By rakesh_n_mehta in forum Web Frameworks
    Replies: 1
    Last Post: 11-21-2008, 04:23 PM
  4. in struts reset was problem
    By sureshBabu in forum Web Frameworks
    Replies: 1
    Last Post: 05-07-2008, 04:26 PM
  5. reset query
    By dd_verni in forum JDBC
    Replies: 0
    Last Post: 11-21-2007, 04:52 AM

Posting Permissions

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