Answer to Question #326938 in C++ for Druce

Question #326938
  1. Input five decimal numbers in one line.
  2. Print out the decimal numbers in one line, separated by spaces, and make sure you only print up to 1 decimal place.
  3. Add the first four decimal numbers and check if their sum is greater than the fifth decimal number. Print out "Yes" if they are.
1
Expert's answer
2022-04-11T07:45:40-0400
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	const int N = 5;
	double arr[N];
	char choice;
	double sum = 0;
	do
	{
		cout << "Please, enter 5 values: ";
		for (int i = 0; i < N; i++)
		{
			cin >> arr[i];
		}
		cout << fixed << setprecision(1);
		for (int i = 0; i < N; i++)
		{
			 cout<< arr[i] << " ";
			 if (i < N - 1)
				 sum += arr[i];
		}
		if (sum > arr[N-1])
			cout << "\nYes";
		cout << "\nDo you want to continue or escape? [Y/N]: ";
		cin >> choice;
	} while (choice == 'Y');
}

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