book question:
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 whenever possible.
Input Validation: Do not accept negative numbers for test scores.
teachers added notes:
Make sure that you use pointers in the program wherever possible.
The program is to ask the user for the number of test scores.
my problem:
I'm at the last stretch of my college semester, and I don't have enough time to really think this one through to finish it. if some one could help me figure out what im doing wrong that would be appreciated
Error:
Severity Code Description Project File Line
Error C2109 subscript requires array or pointer type
part of code it is talking about needs to be pointer according to teacher
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void arrSelectSort(double* arr, int size)
{
double total = 0;
int numTest;
double average;
for (int count = 0; count < numTest; count++)
{
total += numTest[count];
average = total / numTest;
}
}
total += numTest[count]; numTest is an ordinary int so you can'y use [].
Your function should probably look like this:
1 2 3 4 5 6 7 8 9 10 11 12
void arrSelectSort(double* arr, int size)
{
double total = 0;
int numTest; // not needed
double average = 0; // not needed but good practice
for (int count = 0; count < size; count++)
{
total += arr[count];
average = total / numTest;
}
}
Somehow you need to return average otherwise it's lost. So either change the return type to double or pass a reference or pointer to the function.
BTW: The name of the function is totally misleading.