I have a code that displays a game where the lowest score is the aim. In my code, the game can replay as many times as I want and is supposed to display the lowest score from all of the game plays. The changing variable is currentScore. It changes once the game is complete.
The current score can be between 0 and 80.
Here is what I've come up with that is always returning a "NEW LOW SCORE" when it shouldn't always be.
int lowestScore = 0;
if (currentScore < lowestScore) {
lowestScore = currentScore;
System.out.println("Score = " + currentScore + " NEW LOW SCORE!");
System.out.println("Lowest Score = " + lowestScore);
}
else {
System.out.println("Score = " + currentScore);
System.out.println("Lowest Score = " + lowestScore);
}
The output is supposed to show the lowest score value, regardless if it is a new lowest score or not. If it is a new lowest score, it is supposed to show "NEW LOW SCORE" and if not, just the current score and the previous lowest score.
I understand that this if statement doesn't work but I am truly stuck. Any ideas?
Here is a test case of my issue.
game runs and score is 45 outprint: Score = 45 NEW LOW SCORE! Lowest Score = 45
same sequence and game runs again, score is 78 outprint: Score = 78 NEW LOW SCORE! Lowest Score = 78
This is incorrect because in this case, this is what the output should look like:
game runs and score is 45 outprint: Score = 45 NEW LOW SCORE! Lowest Score = 45
same sequence and game runs again, score is 78 outprint: Score = 78 Lowest Score = 45
Aucun commentaire:
Enregistrer un commentaire