7.2k views
4 votes
Read floating-point numbers from input until a floating-point number is read that is not in the range -10.0 to 45.0, both exclusive. Then, find the sum of all the floating-point numbers read before the floating-point number that causes reading to stop. Lastly, output the sum, ending with a newline.

Ex: If the input is -9.0 -6.3 -17.5 -3.6 -5.3 -4.3 -8.6, then the output is:

-15.3

1 Answer

3 votes

Final answer:

This question is about writing a program that continuously reads floating-point numbers from input and sums them up until a number not in the range of -10.0 to 45.0 is encountered, then outputs the sum followed by a newline.

Step-by-step explanation:

The question involves writing a program to read a series of floating-point numbers from the input, summing them up until a number outside the range of -10.0 to 45.0 is encountered. The range is exclusive, meaning any number equal to -10.0 or 45.0 would also terminate the input reading process. To effectively write this program, you would typically use a loop that continually prompts for input and adds input numbers to a running sum. The loop would exit when a number outside of the specified range is entered. Following the loop, you would print out the calculated sum, ensuring to include a newline character.

Here is a simplified pseudocode example:

initialize sum to 0
while true:
read a floating-point number into variable num
if num <= -10.0 or num >= 45.0:
break out of loop
add num to sum
print sum followed by a newline

A real implementation would require actual code using a programming language of choice like Python, C++, etc.

User Witold Skibniewski
by
8.0k points

No related questions found