Answer to Question #280287 in C++ for Collay

Question #280287

3. 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:



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



Multiple lines containing float number on each.



1.1


1.2


1.3


1.4


-1.0


Output



A line containing a float number with two decimal places.



4.00

1
Expert's answer
2021-12-16T04:45:22-0500
#include<iostream>

using namespace std;

int main()
{
	float value;
	float sum=0;
	do
	{
		cout<<"Please, enter a float value: ";
		cin>>value;
		sum+=value;
	}while(value>=0&&sum<=100);
	cout<<"Sum of floating values is "<<sum;
}

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