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.
Here's what I have so far, I need to still throw in something so that it doesn't allow you to input a negative test score.
#include <iostream>
#include <iomanip>
using namespace std;
void selectionSort(double [], double);
void showArray(double []);
int main()
{
double *scores,
total = 0.0,
average;
int numtests,
count;
cout << "How many tests scores need to be averaged? ";
cin >> numtests;
scores = new double[numtests];
cout << "\nEnter in the test scores below.\n";
for (count = 0; count < numtests; count++)
{
cout << "Test score " << (count + 1) << ": ";
cin >> scores[count];
}
for (count = 0; count < numtests; count++)
{
total += scores[count];
}
average = total / numtests;
cout << "The sorted scores are\n";
showArray(scores[count]);
cout << fixed << showpoint << setprecision(2);
cout << "Average Score: " << average << endl;
delete [] scores;
scores = 0;
cin.ignore();
cin.get();
return 0;
}
void selectionSort(double array[], double size)
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for(int index = startScan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
}
}
void showArray(double array[], double size)
{
for (int count = 0; count < size; count++)
cout << array[count] << " ";
cout << endl;
}
I'm getting an error on line 41 with an error code of C2664. Now, as a disclaimer, I did Frankenstein some code together from a source code library from my textbook and I'm thinking that I didn't keep track of my indexes and such as well as I should have. Any ideas on where I went wrong?

New Topic/Question
Reply




MultiQuote




|