Final answer:
The program reads positive integers, sums those greater than 50, and when a negative integer is entered, it computes and prints the average of those numbers.
Step-by-step explanation:
Program to Calculate Sum and Average of Numbers Greater Than 50
The task is to write a program that reads a sequence of positive integers, calculates the sum of all the numbers greater than 50, and then computes the average of these numbers. The program will continue to read numbers until a negative integer, which is used as a sentinel value, is entered. Here's a sample program written in Python:
total_sum = 0
count = 0
while True:
number = int(input("Enter a positive number or a negative number to stop: "))
if number < 0:
break
if number > 50:
total_sum += number
count += 1
if count > 0:
average = total_sum / count
print("Sum of numbers greater than 50:", total_sum)
print("Average of numbers greater than 50:", average)
else:
print("No numbers greater than 50 were entered.")
This program uses a while loop to continuously prompt the user for input until a negative integer is entered. It keeps a running total and count of the numbers greater than 50. After the loop terminates, if the count is greater than zero, the program calculates the average and prints out the sum and average.