156k views
2 votes
Ask the user how many test scores they want to enter from 2-10. Then, use a FOR LOOP to ask them to enter that number of test scores. At the end, calculate the average of those test scores. You may assume the user correctly enters tests scores between 0 and 100 each time. HINT: You will need a SUM variable to help you calculate the average.

User Shenglih
by
7.5k points

1 Answer

3 votes

Final answer:

To calculate the average of user-entered test scores, prompt the user for the number of scores to enter, collect the scores using a FOR LOOP, compute the total sum, and divide by the number of scores to find the average.

Step-by-step explanation:

The question involves writing a program that first asks the user how many test scores they want to enter, with the requirement that they can only enter between 2-10 scores. Once the user specifies the number of scores, a FOR LOOP is used to collect the scores one by one from the user. After all the test scores are entered, the program calculates the average by summing the scores and then dividing by the number of scores entered.

Here is a step-by-step process to achieve this:

  1. Prompt the user to enter the number of test scores they wish to input (between 2 and 10).
  2. Use a FOR LOOP to iterate as many times as the number entered by the user.
  3. During each iteration, ask the user to enter a test score, making sure it's between 0 and 100, and add this to a SUM variable.
  4. After all scores have been entered, calculate the average by dividing the SUM by the number of scores.
  5. Output the calculated average to the user.
User Nasreddin
by
7.1k points