Negative Allergy Instructions: Continuously ask for floating-point values (decimal numbers) using the do…while() loop, sum them all up, and store the total into one variable. The loop shall only terminate for the following reasons: A negative decimal number is inputted (but still included in the total sum) The total sum reaches 100.0 or more Input Format Multiple lines containing float number on each. Input Sample 1.1 1.2 1.3 1.4 -1.0 Output Format A line containing a float number with two decimal places. Output Sample 4.00 Another test case: Input sample -2.3 -4.5 -7.8 Output Sample -14.60 NOTE: Using do-while loop in C programming
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
Negative Allergy
Instructions:
- Continuously ask for floating-point values (decimal numbers) using the do…while() loop, sum them all up, and store the total into one variable.
- The loop shall only terminate for the following reasons:
- A negative decimal number is inputted (but still included in the total sum)
- The total sum reaches 100.0 or more
Input Format
Multiple lines containing float number on each.
Input Sample
Output Format
A line containing a float number with two decimal places.
Output Sample
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images