Pseudo Code Generator

Average Calculation of Positive Numbers Pseudo Code

This pseudo code outlines a method to input numbers repeatedly until a negative number appears, then calculates and displays the average of the positive numbers entered.


Empty image or helper icon

Prompt

Write a REPEAT-UNTIL loop to input numbers until a negative number is entered and then calculate the average of the positive numbers.

Answer

Pseudo Code for Calculating the Average of Positive Numbers

Overview

The following pseudo code describes the logic for repeatedly inputting numbers until a negative number is encountered. Afterward, it calculates the average of the entered positive numbers.

Pseudo Code Structure

Variables

  • number: stores the current input number
  • sum: accumulates the sum of positive numbers (initialized to 0)
  • count: tracks the number of positive inputs (initialized to 0)
  • average: stores the calculated average

Logic

  1. Initialize sum to 0
  2. Initialize count to 0
  3. REPEAT the following steps UNTIL a negative number is entered:
    • Prompt user to input a number and assign it to number
    • IF number is positive THEN:
      • Add number to sum
      • Increment count by 1
  4. IF count is greater than 0 THEN:
    • Calculate average as sum / count
    • Display the average
  5. ELSE:
    • Display a message indicating that no positive numbers were entered

Pseudo Code

INIT sum = 0
INIT count = 0
INIT number = 0

REPEAT
    DISPLAY "Enter a number: "
    INPUT number

    IF number > 0 THEN
        sum = sum + number
        count = count + 1
    ENDIF
UNTIL number < 0

IF count > 0 THEN
    average = sum / count
    DISPLAY "The average of positive numbers is: " + average
ELSE
    DISPLAY "No positive numbers were entered."
ENDIF

Explanation of Steps

  • Initialization: Prepare variables for sum accumulation, count of positive numbers, and the current input.
  • Input Loop: Use a REPEAT-UNTIL loop to continuously prompt for an input number.
  • Condition Check for Positivity: Within the loop, check if the entered number is positive to accumulate its value and count it.
  • Average Calculation and Output: After exiting the loop, check if any positive numbers were recorded to compute and display the average, or notify the user if none were entered.

This pseudo code effectively communicates the logic needed to fulfill the described functionality. It maintains clarity and simplicity, allowing for easy understanding and implementation in various programming languages.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This pseudo code outlines a method to input numbers repeatedly until a negative number appears, then calculates and displays the average of the positive numbers entered.