This lab i am stuck on and was wondering if someone could help me with the source code. Thanks.

I need a program in c++ that asks a user for 20 integers and finds the max, min, average and median of the numbers inputted. It wants code to contain arrays in your functions.

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

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.