Answer to Question #325105 in C++ for nickname

Question #325105

This is similar to the exercise we did in class but with two changes: (1) Use doubles instead of ints; (2) The user will be providing the numbers. Just like the class exercise, output the sum, average, highest, and lowest of the user's numbers. 

 

Output:

This program will ask you to enter 5 numbers with decimal places.

It will then show you the total, average, largest number, and smallest number.

Enter a number:   [user types: 5.2]


Enter a number:   [user types: 9.8]


Enter a number:   [user types: 2.5]


Enter a number:   [user types: 17.5]


Enter a number:   [user types: 7.5]


Total: 42.5

Average: 8.5

Lowest: 2.5

Highest: 17.5


1
Expert's answer
2022-04-11T07:44:08-0400
#include <iostream>


using namespace std;


int main()
{
	double arr[5];
	
	cout << "Please, enter 5 values: ";
	for (int i = 0; i < 5; i++)
	{
		cin >> arr[i];
	}
	double sum = 0;
	double lowest = arr[0];
	double highest = arr[0];
	for (int i = 0; i < 5; i++)
	{
		sum += arr[i];
		if (arr[i] < lowest)
			lowest = arr[i];
		if (arr[i] > highest)
			highest = arr[i];
	}
	double aver = sum / 5;
	cout << "\nTotal: " << sum
		<< "\nAverage: " << aver
		<< "\nLowest: " << lowest
		<< "\nHighest: " << highest;
	
}

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