Hi I'm new to programming and struggling with these application. Here is the error code:
Error C3078 you cannot 'new' an array of unknown bounds line 17
I am struggling to understand and grasp the concept of pointers. Any help is great thanks for looking at my code.
#include <iostream>
#include <iomanip>;
using namespace std;
//function prototypes
int getArray(int num);
void selectionsortArray(int *[], int);
double findAverage(int *scores, int nums);
void showSortedArray(int *[], int);
int main()
{
int *scores = new int[]; // To dynamically allocate an array
double total = 0, //accumulator
average; //to hold average test scores
int testScores, // To hold the amount of test scores the user will enter
count; //Counter variable
// Request the amount of test scores the user would like to enter
cout << "How many test scores do you wish to process: ";
cin >> testScores;
getArray(testScores);
selectionsortArray(&scores, testScores);
cout << "Test scores sorted:\n\n";
showSortedArray(&scores, testScores);
average = findAverage(scores, testScores);
//set precision
cout << setprecision(2) << fixed;
cout << "\tAverage Score\n";
cout << average;
}
int getArray(int num)
{
int *array, ptr; //set array pointer equal to 0
int count;
cout << "\tPlease enter Test Scores by percent:\n";
for (count = 0; count < num; count++)
{
cout << "Test score #" << (count+1)<< ": ";
cin >> array[count];
}
ptr = *array; //Set the ptr to be returned with the array
return ptr; // return ptr
}
void selectionsortArray(int *arr[], int testScores)
{
int startscan, minIndex;
int *minElem;
for (startscan = 0; startscan < (testScores - 1); startscan++)
{
minIndex = startscan;
minElem = arr[startscan];
for(int index = startscan + 1; index < testScores; index++)
{
if (*(arr[index]) < *minElem)
{
minElem = arr[index];
minIndex = index;
}
}
arr[minIndex] = arr[startscan];
arr[startscan] = minElem;
}
}
void showSortedArray(int *arr[], int testScores)
{
for ( int count = 0; count < testScores; count ++)
cout << *(arr[count]) << " \n";
}
double findAverage(int *scores, int testScores)
{
double average = 0;
for (int count = 0; count < testScores; count++)
average += scores[count];
average /= testScores;
return average;
}