Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8714787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:41:02+00:00 2026-06-13T05:41:02+00:00

The homework problem is to write a program that adds together all the scores

  • 0

The homework problem is to write a program that adds together all the scores from a class exam and find the average.

I have two questions. To find the average, you have to divide the total score by the number of test takers. I don’t know how to record how many test takers there are.

Does the method for getting the average go in the while loop or outside the while loop?

import acm.program.*;


public class AvgScore extends ConsoleProgram {
   public void run(){
   println("This program averages the test scores of an exam until the SENTINEL is entered     ."); 


   int total = 0;

   while(true) {
       int score = readInt("enter the test score: ");
       if (score == SENTINEL) break;  
       total += score; 
            }

  println("the average for the class was");

    }

  private static final int SENTINEL = -1; 

  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T05:41:03+00:00Added an answer on June 13, 2026 at 5:41 am

    just add a count variable for every read

    int count=0
    
    while(true) {
      int score = readInt("enter the test score: ");
      if (score == SENTINEL) break;  
      total += score; 
      count++;
    }
    

    the calculate the average

    double avg = (double)total/count;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my homework for my C class, we have to write a program that
This is a homework assignment, I have to write a program that reads a
I have a homework question that says: Problem 1: Given the array [ 22
Problem: Write a program Deal.java that takes an command-line argument N and prints N
I have done a homework assignment, here is the problem statement: Your program should
I have a homework problem that I really don't know how to start. Here
For a homework problem, I need to write a Java method to find the
I have a homework assignment that I am supposed to write a http server
Hey all, I have a Java problem. For my senior research class, I'm pretty
I have a question about my homework problem. Here is the problem: Write a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.