Below is the program I have written yet I can't seem to get it to work right. I have to believe that there is also I more efficient way to write this program. A little direction as to where I might have gone wrong would be great.


// Purpose: generate a class average for entered test scores
// Input: # of tests, test scores
// Output: total number of tests, average score of tests

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
//declare variables
short numberOfTests = 0;
short testScores = 0;
short scoreGrade = 0;
short sum = 0;
short testNumber = 1;
double averageScore = 0.0;

do //begin loop
{
cout << "Enter the number of tests: ";
cin >> numberOfTests;

if (numberOfTests >= 1 && numberOfTests <= 100)
cout << "You entered " << numberOfTests << " as the number of tests. " << endl;
else
cout << "The number must be between 1 and 100 (inclusive). ";
//end if
} while (numberOfTests < 1 || numberOfTests > 100);

testScores = numberOfTests;

while (numberOfTests > 0)
{
cout << "Enter the score for test #" << testNumber << ": " << endl;
cin >> scoreGrade;

if (scoreGrade >= 0 && scoreGrade <= 100)
{
sum += scoreGrade;
testNumber += 1;
numberOfTests -= 1;
}

cout << "You must enter a valid number between 0 and 100 (inclusive) as a score. ";
} //end while

averageScore = sum / testScores;
cout << "There were a total of " << testScores << " test scores. " << endl;
cout << "The average of all the test scores is: " << averageScore << endl;

cin.get();
return 0;
}