Answer to Question #287122 in C for jay

Question #287122

Negative Allergy

by CodeChum Admin

Whole numbers are great, but I think we should also pay attention to decimal numbers, too.


So, how about we make a program that involves a lot of decimals?


Instructions:

  1. Continuously ask for floating point values (decimal numbers) using the do…while() loop, sum them all up, and store the total into one variable.
  2. The loop shall only terminate for the following reasons:
  3. A negative decimal number is inputted (but still included in the total sum)
  4. The total sum reaches 100.0 or more

Input


1. A series of float numbers

Output


The first multiple lines containing message prompts for float numbers.

The last line contains the sum with 2 decimal places.


Enter a number: 1.1
Enter a number: 1.2
Enter a number: 1.3
Enter a number: 1.4
Enter a number: -1.0
Sum = 4.00
1
Expert's answer
2022-01-14T04:36:23-0500


#include <stdio.h>




int main()
{
	float number;
	float sum=0;
    do{
		printf("Enter a number: ");
		scanf("%f",&number);
		sum+=number;
	}while(sum<100 && number>0);
    
	printf("Sum = %.2f\n",sum);
	scanf("%f",&sum);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS