Answer to Question #310898 in C++ for Secret Agent

Question #310898

As I've said before, there are three types of numbers: the positive, the zero, and the negative ones. Today, we shall pay attention only to the negative ones now. Make a loop that will accept random decimal/float numbers. When the user inputs 0, the loop will terminate and then output the sum of all negative numbers inputted in 3 decimal places.


Let's code this.


Input

Multiple lines containing a decimal.

2.4434
-1.3433
-2.444
6.432
0

Output

A line containing a decimal with three decimal places.

-3.787





1
Expert's answer
2022-03-16T10:24:03-0400

Here is program:

int main()
{


	const int size = 6;
	double dec[size]{};
	double total;
	for (int i = 0; i < size; i++)
	{
		cin >> dec[i];
		total += dec[i];
	}
	total = total / size;
	cout << total << endl;
}

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