the specific error is here:
sortScores(ptrScores, numScores);
Here is the code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//function prototypes
void sortScores (double *, int);
void showArray (double *, int);
void avgScores (double *, int);
struct Scores
{
string name;
int score;
};
int main ()
{
int numScores = 0;
double *ptr = NULL; //pointer for dynamic array size
//get number of test scores
cout << "How many test scores will you enter? ";
cin >> numScores;
cout << endl;
Scores *ptrScores;
ptrScores = new Scores [numScores];
for (int score = 0; score < numScores; score++)
{
cout << "Enter a student name: ";
cin >> ptrScores[score].name;
cout << "Enter " << ptrScores[score].name << "'s grade: ";
cin >> ptrScores[score].score;
if (ptrScores[score].score < 0)
{
cout << "Please only enter positive numbers.";
cout << "Please enter the grade again: ";
cin >> ptrScores[score].score;
}
}
sortScores(ptrScores, numScores);
return 0;
}
/***************sortScores******************/
//This function sorts test scores in an array
void sortScores(double *array, int size)
{
int temp;
bool swap;
//sort array in ascending order
do
{ swap = false;
for (int count = 0; count < (size-1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
}while(swap);
}

New Topic/Question
Reply



MultiQuote




|