Answer to Question #328737 in C++ for sugar

Question #328737
  1. Input five float numbers.
  2. Print out the float numbers in one line, separated by spaces, and make sure you only print up to 1 decimal place.
  3. Add the first four float numbers and check if their sum is greater than the fifth float number. Print out "Yes" if they are.




1
Expert's answer
2022-04-14T09:56:36-0400
#include <iostream>
#include <iomanip>

using namespace std;

void main()
{
	float arr[5];
	cout << "Please, enter 5 numbers: ";
	for (int i = 0; i < 5; i++)
	{
		cin >> arr[i];
	}
	float sum = 0;
	cout << fixed << setprecision(1);
	for (int i = 0; i < 5; i++)
	{
		cout<<arr[i]<<" ";
		if (i != 4)
			sum += arr[i];
	}
	cout << endl;
	if (sum > arr[4])
		cout << "Yes";
}

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