Answer to Question #346035 in C for Chariz

Question #346035

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



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-05-30T08:17:02-0400
#include <stdio.h>
int main()
{
	float number;
	float result = 0;
	do
	{
		printf("Enter a number: ");
		scanf_s("%f", &number);
		result = result + number;
	} while (number > 0 && result < 100);
	printf("Sum = %.2f", result);
	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
APPROVED BY CLIENTS