Not Yet Answered # arrays in functions

daviddoria 334 firstPerson 761

0

You should definitely use std::vector instead of basic arrays.

No one is going to help you unless you show that you have tried yourself first.

Dave

0

1st Create an array of 20 elements like so :

```
const int MAX_STUDENTS = 20;
int Scores[MAX_STUDENTS] = {0}; //create and initialize all 20 elements to 0
```

next you need to ask the user to enter 20 integers. Using a for loop is

a good idea. For example, you can do something like so :

```
for i = 0 to MAX_STUDENTS
cin >> Scores[i]
```

now you need to find four things, the max , min, average, and median.

The "max" is the highest number in the array

The "min" is the lowest number in the array

The "average" is the total addition of all numbers in the array divided by the number of elements in the array

The "median" is the middle number, when the array is sorted.

To get all of those, I would suggest you to sort the array using simply

a bubble sort. Maybe like so :

```
for(int i = 0; i < MAX_STUDENTS; ++i){
for(int j = 0; j < MAX_STUDENTS; ++j){
if(Scores[i] > Scores[j]){ std::swap(Array[i],Array[j]); }
}
}
```

By sorting the array, you can find the min and max easily. You can

then find the average by using a for loop. You can also find the median

easily as well. Give it a go and come back if you have trouble.

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

the function that I created to find the ...

Hi. so this is actually a continuation from another question of mineHere but i was advised to start a new thread as the original question was already answered.

This is the result of previous question answered :

code for the listbox - datagridview interaction

At the top of the code ...

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`