### Array & Pointer Issue

I need to write a program that averages user-entered test scores, assembles them in ascending order, and uses pointer notation wherever possible.

I am tired, and have been working on this for upwards of 4-5 hours.
Anybody know how to help?

Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
void arrSelectSort(int *[], int);
void showArrPtr(int *[], int);
int findAverage(int, int);
int main()
{
int x = 0;
int sum = 0;
int *ptr = nullptr;
ptr = &x;
int tests[1000];
cout << "How many tests are you defining: ";
cin >> x;
for (int i = 0; i < *ptr; i++)
{
cout << "Enter test " << i + 1 << " score: ";
cin >> tests[i];
sum = sum + tests[i];
}
cout << "The average is: " << findAverage(sum,x);
cin.get();
cin.get();
int NUM_TESTS = x; //This is the problematic
int tests[NUM_TESTS] = *ptr; //part.
int *arrPtr[NUM_TESTS] = {nullptr}; //
// I need a const int, but x is not a const int... Is this problem small?
// Or will I need to restructure and redo my code completely?
for (int count = 0; count < NUM_TESTS; count++)
arrPtr[count] = &tests[count];

arrSelectSort(arrPtr, x);

return 0;
}
int findAverage(int sum, int x)
{
return sum / x;
}

void arrSelectSort(int *arr[], int size)
{
int startScan, minIndex;
int *minElem;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minElem = arr[startScan];
for (int i = startScan + 1; i < size; i++)
{
if (*(arr[i]) < *minElem)
{
minElem = arr[i];
minIndex = i;
}
}
arr[minIndex] = arr[startScan];
arr[startScan] = minElem;
}
}

void showArrPtr(int *arr[], int size)
{
for (int count = 0; count < size; count++)
cout << *(arr[count]) << " ";
cout << endl;

}
Topic archived. No new replies allowed.