Hello...I'm trying to write this program answering this question and I keep getting C2440 errors and C2664 errors and I did some research but couldn't find anything on how to correct it.
The question says : Write a program that dynamically allocates an array large enough to hold a user defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation wherever possible.
This is what I have ,any help would be greatly appreciated .thanks
#include <iostream>
#include <iomanip>
using namespace std;
void arrAscendingOrder(double *[], int);
void showArrPtr(double *[], int);
void showAverage(double , int);
int main()
{
double *scores, //To dynamically allocate an array
total=0.0, //Accumulator
average; //To hold the averge scores
int numScores; //To hold the number of test scores
//Get the number of test scores.
cout<<"How many test scores would you like to process?";
cin>>numScores;
//Dynamically allocate an array large enough to hold that many
//test scores
scores = new double[numScores];
//Get the test score for each test
cout<<"Enter the test scores below.\n";
for (int count=0; count<numScores; count++)
{
cout<<"Test "<<(count+1)<<": ";
cin>> scores[count];
}
//Calculate the total scores
for (int count=0; count<numScores; count++)
{
total += scores[count];
}
arrAscendingOrder (scores, numScores);
showArrPtr (scores, numScores);
showAverage(total, numScores);
//Free dynamically allocated memory.
delete [] scores;
scores =0; //make sales point to null.
return 0;
}
void arrAscendingOrder(double *array[], int size)
{
int startScan, minIndex;
int *minElem;
for (startScan=0; startScan<(size-1); startScan++)
{
minIndex =startScan;
minElem = array[startScan];
for (int index=startScan+1; index<size; index++)
{
if (*(array[index])< *minElem)
{
minElem = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minElem;
}
}
void showArrPtr(double *array[], int size)
{
for (int count=0; count< size; count++)
cout<< *(array[count])<<" ";
cout<<endl;
}
void showAverage(double total, int numScores)
{
double average;
//Calculate the average
average = total / numScores;
//Display the results.
cout<<fixed<<showpoint<<setprecision(2);
cout<<"Average Score: "<<average<<endl;
}