Note that there are some explanatory texts on larger screens.

plurals
  1. POHaving problems with placing braces at the right places?
    primarykey
    data
    text
    <p>Am kinda new to programming, my problem that i've tried hard trying to figure out is this. My console application ask the user how many test score are do they want to input for it to calculate the average and total of all scores. if they enter 3 it ask for them to input 3 test scores and then it displays the average and total of all scores. it then ask them do they want to continue or end the program, if they enter yes continue it should start all over. My issue is when i say yes it doesn't clear the total or score count it just continues from the previous and just adds the new scores to that. </p> <pre><code> import java.util.Scanner; public class TestScoreApp { public static void main(String[] args) { // display operational messages System.out.println("Please enter test scores that range from 0 to 100."); System.out.println("To end the program enter 999."); System.out.println(); // print a blank line // initialize variables and create a Scanner object int scoreTotal = 0; int scoreCount = 0; int testScore = 0; Scanner sc = new Scanner(System.in); String choice = "y"; // get a series of test scores from the user while (!choice.equalsIgnoreCase("n")) { System.out.println("Enter the number of test score to be entered: "); int numberOfTestScores = sc.nextInt(); for (int i = 1; i &lt;= numberOfTestScores; i++) { // get the input from the user System.out.print("Enter score " + i + ": "); testScore = sc.nextInt(); // accumulate score count and score total if (testScore &lt;= 100) { scoreCount = scoreCount + 1; scoreTotal = scoreTotal + testScore; } else if (testScore != 999) System.out.println("Invalid entry, not counted"); } double averageScore = scoreTotal / scoreCount; String message = "\n" + "Score count: " + scoreCount + "\n" + "Score total: " + scoreTotal + "\n" + "Average score: " + averageScore + "\n"; System.out.println(message); System.out.println(); System.out.println("Enter more test scores? (y/n)"); choice= sc.next(); } // display the score count, score total, and average score } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload