so i'm new to c++ and tying to write a program that will hold test scores then they have to be arrange in ascending order and average them all tighter at then end. I got this far and keep getting an error of cannot convert parameter 1 from int to int* for "showAverage". I am not sure what is wrong please help!
Code:
//This program will hold a user-defined number of test scores
//Then it will sort them in ascending order and average them.
#include <iostream>
using namespace std;
//function prototype
void arrSelectSort (int *, int);
void showAverage (int *, int);
void showArrPtr (int *, int);
int main()
{
int *scores, //to dynamically allocate an array
average, //to hold the average test score
total=0, //accumulator
numTest, //to hold the number of test scores
count; //counter variable
//get the number of test scores.
cout <<"Test Scores" << endl;
cout << "How many test scores do you need to average? ";
cin >> numTest;
//dinamically allocate an array large enough to hold that many test scores.
scores=new int [numTest];
//get the test score
cout <<"Enter the test scores to be average: " <<endl;
for (count=0; count<numTest; count++)
{
cout<<"Test " << (count+1) << " : ";
cin >> scores [count];
//do not accept negative test scores numbers
while (scores <0)
{
cout <<"Enter a number greater than 0";
cin >> scores [count];
}
}
//calculate the total scores together
for (count=0; count<numTest; count++)
{
total+=scores[count];
}
//sort the elements of the array of pointers
arrSelectSort(scores, scores[count]);
//display the test scores in ascending order
cout<<"The test scores in ascending order are: " << endl;
showArrPtr (scores,scores[count]);
//display the average test score
showAverage (total, numTest);
//free allocated memory
delete [] scores;
scores=0; //make scores point to null.
return 0;
}
//******************************************************
//definition of function showAverage
//this funtion displays the average number of test scores
//***************************************************
void showAverage (int total, int numTest)
{
int average;
//calculate the average
average=total/numTest;
//display the results.
cout<<"Average Score: "<<average<<endl;
}
//**************************************************
//definition of function arrSelectSort
//this funtion will perform the ascending order selection sort
//*****************************************************
void arrSelectSort (int *arr[], int size)
{
int startScan;
int minIndex;
int *minElem;
for (startScan=0; startScan<(size-1); startScan++)
{
minIndex=startScan;
minElem=arr[startScan];
for (int index= startScan + 1; index <size; index++)
{
if (*(arr[index])<*minElem)
{
minElem=arr[index];
minIndex=index;
}
}
arr[minIndex] = arr[startScan];
arr[startScan] = minElem;
}
}
//*******************************************************
//definition of function showArrayPtr
//this function displays the contents of the array pointed to by arr
//*********************************************************
void showArrPtr (int *arr[], int size)
{
for (int count=0; count <size; count++)
cout<<*(arr[count])<<" ";
cout<<endl;
}