#include <iostream>
using namespace std;

void ascendingorder(int *a, int *b, int c);
int average(int *a, int b);

int main()
{
	int SIZE;

	cout << "Enter Amount of Test Scores: ";
	cin >> SIZE;
	while (SIZE <= 0)
	{
		cout << "Enter Positive Value" << endl;
		cout << "Enter Amount of Test Scores: ";
		cin >> SIZE;
	}

	int *test = new int[SIZE];
	int *testnumber = new int[SIZE];

	for(int count = 0; count < SIZE; count++)
	{
		cout << "Test " << (count + 1) << ": ";
		cin >> *(test + count);
		while(*(test + count) < 0)
		{
			cout << "Please Enter Positive Value." << endl;
			cout << "Test " << (count + 1) << ": ";
			cin >> *(test + count);
		}

		*(testnumber + count) = count + 1;
	}
	cout << "\n";
	ascendingorder(test, testnumber, SIZE);

	for(int count = 0; count < SIZE; count++)
		{
		cout << "Test " << *(testnumber + count)
			 << ": " << *(test + count) << endl;
		}
	cout << "\n";

	int averagescore = average(test, SIZE);

	cout << "Average Score: " << averagescore << endl;

	delete [] test;
	delete [] testnumber;

	return 0;
}

void ascendingorder(int *a, int *b, int c)
{
	int startscan, minIndex;	//Used to scan through the array
	int minValue;				//Holds lowest value found
	int temp;					//Temporary Position
//
//Initializing For Loop
	for (startscan = 0; startscan < (c - 1); startscan++)
	{
		minIndex = startscan;		//Assigns starting position as lowest
		minValue = *(a + startscan);	//Assigns starting number as lowest
//
//Searches for lowest account number value
		for (int index = startscan + 1; index < c; index++)
		{
			if(*(a + index) < minValue)
			{
				minValue = *(a + index);	//Updates lowest number value
				minIndex = index;		//stores position of lowest value
			}
		}
//
//Swaps Values
	*(a + minIndex) = *(a + startscan);
	*(a + startscan) = minValue;

	temp = *(b + minIndex);
	*(b + minIndex) = *(b + startscan);
	*(b + startscan) = temp;
	}
}

int average(int *a, int b)
{
	int total = 0;
	int average;
	for(int count = 0; count < b; count++)
	{
		total += *(a + count);
	}
	average = total / b;
	return average;
}
