Finding the average, Highest and Lowest Number of an Array

Having trouble figuring out how to find the average, lowest and highes

Page 1 of 1

1 Replies - 4827 Views - Last Post: 01 December 2009 - 09:27 PM Rate Topic: -----

#1 mjy5027  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 12
  • Joined: 01-October 09

Finding the average, Highest and Lowest Number of an Array

Post icon  Posted 01 December 2009 - 09:15 PM

#include <iostream>

using namespace std;

// Write a program that prompts the user for test scores (doubles). 
// The user enters -1 to stop the entry. After all of the test scores have been entered, calculate the average, 
// the highest and the lowest test score. Use the code below as a template. 
// Make sure you respond appropriately when no test scores are entered. Use the following screen shots as a guide.

int main()
{
	double scores[75];
	int counter = -1;
	do
	{
		counter++;
		cout << "Please enter a score (enter -1 to stop): ";
		cin >> scores[counter];

	} while (scores[counter] >= 0);

	for (int y = 0; y > counter; y++)
	{
		double x, lowest = 100, highest = 0;
		
		if (lowest > scores)

			lowest = x;

		if (highest < x)

			highest = x;

		cout << "Highest is " << highest << endl;
		cout << "Lowest is " << lowest << endl;

	}
		
		
}



I am having trouble finding the average of the numbers entered. When I enter -1 the program should output the average first, then the highest number, and lastly the lowest number. I am not sure how to work with this type of program I am a noob and stuck. I have been working on this program for a long long time now and any little advice or help would be appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Finding the average, Highest and Lowest Number of an Array

#2 GenHornet18  Icon User is offline

  • Darken the Radar

Reputation: 36
  • View blog
  • Posts: 629
  • Joined: 19-October 09

Re: Finding the average, Highest and Lowest Number of an Array

Posted 01 December 2009 - 09:27 PM

you're not using array's correctly, review what an array is and how to work with them.

To find the maximum element in an array loop through each element, comparing each element in the array against the the greatest amount which will also be an element in the array. Do the same for the minimum checking each element. For the average create a new variable to hold the total amount and loop through the array adding each element on to new variable. Then divide this new variable by the total amount of elements in the array; you have your average.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1