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.
Re: Basic Java Calculating Cumulative Score - Hangman Help
Quote:
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.
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.
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