### Program that finds average of test after dropping lowest

Why do I get a weird number for the average after I drop the lowest test grade?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120`` ``````// Average of test scores //Gaddis 7th edition number 3 //Libraries #include #include using namespace std; //Function prototypes void sort(float *, int); void sortAry(int *, int); void minPos(int *,int ,int); void swap(int *, int*); //Eecution begins here int main() { //Declare variables int *testScores, total = 0; float average; int numTest, const count=0; //Input cout << "How many test scores are you entering? "; cin >> numTest; //Allocte array testScores = new int[numTest]; cout << "Enter the test scores below.\n"; for (int count = 0; count < numTest; count++) { cout << "Test Score " << ": "; cin >> *(testScores + count); if(*(testScores + count)<0) { cout << "Test score cannot be negative, please try again" << endl; count --; } } cout << endl; //Adding the test Scores total=0; for (int count = 0; count < numTest; count++) { total += *(testScores+count); } //Calculate the average test scores average = total / numTest; cout << "The average of all the test scores is " << setprecision(2) << fixed << average << endl; cout << endl; //Display the Test Scores in ascending order cout << "The test scores in ascending order are: "; sortAry(testScores, numTest); for(int i=0; i*(testScores+i)) swap(testScores+pos,testScores+i); } } void swap(int *a,int *b) { //Swap in place *a=*a^*b; *b=*a^*b; *a=*a^*b; } ``````
Last edited on
Reset total to zero before `for(int i = 1; i < numTest;i++)`. And divide by (numTest-1).
Topic archived. No new replies allowed.