Test Average

Can someone explain to me why my array size doesn't let me run the program

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960`` `````` #include #include using namespace std; int main() { // Declare variables int SIZE; int testScores[SIZE]; int numStudents; int stuCount; int testCount; double testTotal; double average; int sum; // This is the work done in the housekeeping() function // Get user input to control loop cout << "Enter number of students: "; cin >> numStudents; SIZE = numStudents; // Initialize accumulator variable to 0 testTotal = 0; // This is the work done in the detailLoop() function // Loop for each student stuCount = 0; cout << "How many tests will each student be taking?"; cin >> testCount; //User enters test scores of amount of students taking the test while (stuCount <= numStudents) { cout << "Enter the test score for " numStudents " students"; cin >> testScores[]; stuCount++; } //Gets the sum of the array for (int a=0; a=
Hello ddaniel10,

Because "SIZE" needs to be a constant as in `constexpr int SIZE{ 10 };` or `const int SIZE{ 10 };`. The first is a newer form. The capital letters let you know that it is defined as a constant and can not be changed. This means line 23 will not work.

When you define an array the size of the array needs to be a constant value. This could be a variable defined as a constant or a number like 10. At compile time the compiler needs to know how much space to set aside for the array. That is why it needs to be a fixed number. If you need an array based on a variable then you will need to create a dynamic array.

I will have to check into the rest of the program in a bit.

Hope that helps,

Andy
Hello ddaniel10,

You should compile the program before you post the code. This way if there are any errors that you do not understand you can add them to the message.

Once I made some changes I found more problems.

The while loop is not doing what it should. It could be made to work, but a for loop or loops would work better. As it is it is not working to collect the test scores from all the students.

Variables like "testTotal" and "stuCount" lines 26 and 31. These variables can be initialized when they are defined unless there is a need to do it later.

You need to re think what you need to do and make the program do it.

Hope that helps,

Andy
Topic archived. No new replies allowed.