Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Basic Java Calculating Cumulative Score - Hangman Help

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Basic Java Calculating Cumulative Score - Hangman Help

    I am programming a Hangman Console game. Have done most of it by stuck whereby I need to save cumulative score. Assignment reads:

    If word is complete then
    • add the score (5 mins the number of wrong guesses for that word) to the cumulative score


    The winner automatically plays again. So want to display the cumulative score when player loses. (Total Scores of all the number of plays)

    Please help me how to go about it. Or give me a sample code to work from to get an idea.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Basic Java Calculating Cumulative Score - Hangman Help

    need to save cumulative score.
    Usually you use a variable to accumulate a value.
    Define a variable that is saved over the life of the execution of the code and add the scores to it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    15
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Basic Java Calculating Cumulative Score - Hangman Help

    Have tried that but it, needs to be initialized so do it by using "int cumScore = 0;" now when I call initGame() for the user to play again I think it sets the cumScore to 0 again.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Basic Java Calculating Cumulative Score - Hangman Help

    Initialize it only one time before any iterations/loops, not every time a new iteration starts.

    See http://www.javaprogrammingforums.com...-sum-code.html
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java Hangman!
    By JavaManNoob in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 28th, 2012, 11:17 PM
  2. Major Help, SAVE ME!! Java Dice Game - Keep Score?
    By jbarcus81 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 4th, 2012, 06:36 AM
  3. Cumulative sum of entries
    By CSUTD in forum What's Wrong With My Code?
    Replies: 9
    Last Post: November 1st, 2011, 06:32 PM
  4. [SOLVED] Cumulative array
    By spaggwoo in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 23rd, 2011, 09:54 AM
  5. Java hangman game help...
    By AnotherNoob in forum AWT / Java Swing
    Replies: 16
    Last Post: December 4th, 2009, 11:17 PM

Tags for this Thread