# Finding the average, Highest and Lowest Number of an Array

Page 1 of 1

## 1 Replies - 6275 Views - Last Post: 01 December 2009 - 09:27 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=142757&amp;s=b266f625c1b88f74a74dfa4e9519a3ef&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mjy5027

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

# Finding the average, Highest and Lowest Number of an Array

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

Reputation: 36
• 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.