Question

In: Computer Science

Define a problem with user input, user output, While Statement and some mathematical computation. Write the...

Define a problem with user input, user output, While Statement and some mathematical computation. Write the pseudocode, code and display output.

Solutions

Expert Solution

Problem statement: Finding the average of a student subject marks entered by the user. The average is the sum of the marks, divided by the total number of subjects. The program will ask the user to enter one student subject detail marks at a time. It will keep count of the number of integers entered, and it will keep a running total of all the number of subjects it has read so far. This will be done by using while statement.

pseudocode:

Let avg      // The avg of the integers entered by the user.
Let sum=0       // The avg of the integers entered by the user.
Let total_subject = 0   // The number of subjects entered by the user.
while there are more subjectmarks to process:
    Read an subject_marks
    Add it to the sum
    Count the total_subject
Divide sum by total_subject to get the average of all subject 
Print out the average

code:


import java.util.*;
public class Main {
        
   public static void main(String[] args) {
      
      int subject_marks;   // subject_marks input by the user.
      int sum;           // The sum of the subject_marks.
      int total_subjects;         // The number of subjects.
      double average;    // The average of the subject_marks.
      
      Scanner s=new Scanner(System.in);
      /* Initialize the summation and counting variables. */
      
      sum = 0;
      total_subjects = 0;
      
      /* Read and process the user's input. */
      
      System.out.print("Enter your first subject_marks: ");
      subject_marks = s.nextInt();
      
      while (subject_marks != 0) {
         sum += subject_marks;   // Add inputNumber to running sum.
         total_subjects++;              // Count the input by adding 1 to count.
         System.out.print("Enter your next subject_marks, or 0 to quit the program: ");
         subject_marks = s.nextInt();
    
      }
      
      /* Display the result. */
      
      if (total_subjects == 0) {
         System.out.println("You didn't enter any subject_marks!");
      }
      else {
         average = ((double)sum) / total_subjects;
         System.out.println();
         System.out.printf("Their average is %1.3f.\n", average);
      }
 
   } // end main()
   
} // end class 

output


Related Solutions

Define a java problem with user input, user output, Do While Statement and some mathematical computation....
Define a java problem with user input, user output, Do While Statement and some mathematical computation. Write the pseudocode, code and display output.
Define a problem with user input, user output, Switch and some mathematical computation. Write the pseudocode,...
Define a problem with user input, user output, Switch and some mathematical computation. Write the pseudocode, code and display output. Include source code and output. If no output explain the reason why and what you are going to do make sure it does not happen again aka learning from your mistakes. Problem: Pseudocode: Code: Output:
Define a problem with user input, user output, -> operator and destructors. C ++ please
Define a problem with user input, user output, -> operator and destructors. C ++ please
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
C++ please. Define a problem with user input, user output, Pointer, with const and sizeof operator.
Write a program in C, that uses standard input and output to ask the user to...
Write a program in C, that uses standard input and output to ask the user to enter a sentence of up to 50 characters, the ask the user for a number between 1 & 10. Count the number of characters in the sentence and multiple the number of characters by the input number and print out the answer. Code so far: char sentence[50]; int count = 0; int c; printf("\nEnter a sentence: "); fgets(sentence, 50, stdin); sscanf(sentence, %s;    for(c=0;...
Ask the user to input a series of numbers, write a C# program to output the...
Ask the user to input a series of numbers, write a C# program to output the sum, max, and min. Be sure to do error checking if the user input is not a number.
USING THE IF STATEMENT & Scanner for input and println for output - Write a java...
USING THE IF STATEMENT & Scanner for input and println for output - Write a java program where the user enters a temperature as a whole number from input, and outputs a “most likely” season [either SUMMER, SPRING, FALL or WINTER] depending on the temperature entered. SUMMER would be 90 or higher SPRING   would be 70 to less than 90 FALL       would be 50 to less than 70 WINTER would be less than 50 Consider it an error if the...
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
Write a program that uses a while statement to read integers from the user and prints...
Write a program that uses a while statement to read integers from the user and prints the sum, average, and largest of these numbers. The input should terminate if the user enters 999. The average should be output with 4 digits of precision. c++ please ASAP
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT