I need help with pointers, I am getting the following error:
error C2664: 'showArray' : cannot convert parameter 1 from 'int *' to 'int *[]' for both of these functions:
Code:
void sort(int *[], int);
void showArray(int *[], int);
I have run out of ideas, please help!
Code:
#include <iostream>
#include <iomanip>
using namespace std;
//Function prototypes
int getnumtestscores();
void gettestscores(int[], int);
void sort(int *[], int);
void showArray(int *[], int);
double average(int [], int);
int main()
{
int numts = getnumtestscores();
int *testscores;
testscores = new int[numts]; //To dynamically allocate an array
gettestscores(testscores, numts);
cout << "The average of all " << numts << " test scores is: "
<< fixed << showpoint << setprecision(2)
<< average(testscores, numts);
cout << "The testscores are: " << showArray (testscores, numts);
cout << "The numbers sorted are: " << sort (testscores, numts);
// Free dynamically allocated array in memory
delete [] testscores;
// Make scores point to null
testscores = 0;
return 0;
}
int getnumtestscores()
{
int num;
cout << "\n How many test scores do you want to enter : ";
for(;;) // loop forever ... until return
{
cin >> num;
return num;
}
}
void gettestscores(int testscores[], int numts)
{
cout << "What are the testscores for the students?\n";
for (int count = 0; count < numts; count++)
{
cout << "Testscore " << setw(2) << (count+1) << ":";
cin >> testscores[count];
if (testscores < 0) //Input validation
{
cout << "An invalid score was entered, please enter a score more than 0\n";
}
}
}
void sort(int *array[], int numts)
{
int lowIndex, *lowest;
for (int count = 0; count < (numts-1); count++)
{
lowIndex = count;
lowest = array[count];
for (int index = count + 1; index < numts; index++)
{
if (*(array[index]) < *lowest)
{
lowest = array[index];
lowIndex = index;
}
}
array[lowIndex] = array[count];
array[count] = lowest;
}
}
void showArray(int *array[], int numts)
{
for (int count = 0; count < numts; count++)
cout << *(array[count]) <<" ";
cout << endl;
}
double average(int *array[], int numts)
{
int total = 0, *testscores; //Accumulator
double average; //To average testscores
for (int count = 0; count < numts; count++)
total +=testscores[count];
return total/numts;
}