I am quite new to java programming
Preparing a scoreboard and in Java Program, I am struggling with Carry Over score in the for loops
appreciate if I can have simple example of how I can prepare such board in java.
Round 1
- Carry Over Score : 0
- Current: 5
- Total: 5
Round 2
- Carry Over Score : 5
- Current :10
- Total 15
Round 3
- Carry Over Score: 15
- Current: 5
- Total : 20
Round 4
- Carry Over Score: 20
- Current: 7
- Total : 27
>Solution :
I assume this is what you intend to do:
int carryOverScore = 0;
int currentScore = 0;
int totalScore = 0;
int gameRounds = 5;
for (int i = 0; i < gameRounds; i++) {
currentScore = 5; //you should use some method to calculate current score instead of hardcoding the value
carryOverScore = totalScore;
totalScore = totalScore + currentScore;
System.out.println("Carry over: " + carryOverScore);
System.out.println("Current: " + currentScore);
System.out.println("Total: " + totalScore);
}