Errors with code!!

I am having to write a program that asks the user how many students to process, then reads in the scores for two items, an exam score and lab average, for that many students, then calculates and displays a table of the students’ grade information.

Here is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include<iostream>
#include<iomanip>
#define MAX_STUDENTS 20 //sets a default value that can be used for initializing the arrays
using namespace std;
int getStudentCount(); 
void getExamScores(int, double[]); 
void getLabScores(int,double[]); 
void calculatePointGrades(double[], double[], int, double[]);
void calculateLetterGrades(double[],char[], int); 
void showGradeData(double[],double[],char[], double[],int); 
double arrayExamAve(int, double[]); 
double arrayLabAve(int, double[]); 
void arrayPointGrades(char[], double[], int);
char arrayLetterGrades(double[]);
// Declare functions here, include the necessary parameters here and in the actual functions below.
// (once the function prototypes are created, the main()
// function can be moved back to the top of the code.)
// Declare the arrays here
int main(){ // controls program sequence (can be moved back to the top once the function parameters are defined.)
    int numStudents = getStudentCount();
    cout << "You entered: " << numStudents <<" Students!" <<endl;
    double arrayExam[numStudents];
    getExamScores(numStudents,arrayExam);
    double arrayLab[numStudents];
    getLabScores(numStudents,arrayLab);
//getLabScores(numStudents,arrayLabAve[lScores]);
//calculatePointGrades(arrayLabAve[lScores],arrayExamAve[eScores],getStudentCount,arrayPointGrades[grades]);
//calculateLetterGrades(arrayPointGrades[grades],arrayLetterGrades[grades],getStudentCount);
//showGradeData(arrayExamAve[eScores],arrayLabAve[lScores],arrayLetterGrades[grades],arrayPointGrades[grades],getStudentCount);
cout<<"processing has completed in main()"<<endl;// this statement is used for intial test and debugging
cin.ignore(2);
}
 
int getStudentCount(){// Ask for and store the number of students from user
    int numStudents= 0;
    while (numStudents<1 || numStudents>MAX_STUDENTS){
        cout << "Please enter the number of students: ";
        cin >> numStudents;
    }
cout << endl;// this statement is used for intial test and debugging
return numStudents; // returns the user entered number of students to main
}
 
void getExamScores(int numStudents, double *arrayExam){// Gets exam scores from user, loads the array
    cout << "Please enter the exam grades for each student:"<< endl;
    for (int eScores = 0; eScores <numStudents; eScores++){
        cout<<"student "<<eScores+1<<" grade=";
        cin >> arrayExam[eScores];
        cout << endl;// this statement is used for intial test and debugging
    }
}
 
 
void getLabScores(int numStudents, double *arrayLab){// Gets exam scores from user, loads the array
    cout << "Please enter the exam grades for each student:"<< endl;
    for (int lScores = 0; lScores <numStudents; lScores++){
        cout<<"student "<<lScores+1<<" grade=";
        cin >> arrayLab[lScores];
        cout << endl;// this statement is used for intial test and debugging
    }
}
 
void calculatePointGrades(double arrayLabAve[], double arrayExamAve[], int getStudentCount,double arrayPointGrades[] )// Calculates the student's numeric grade, loads the point grade array
{ 
// int grade=0;
// int sum=0;
// int pointGrade=0;
// for (sum = 0; sum <= numStudents; sum++)
// { sum = arrayLabAve[] + arrayExamAve[];
// pointGrade = sum/2;
// cin >> arrayPointGrades[grade];
// cout << endl;
// }
// 
//// this statement is used for intial test and debugging
//return; // returns no values to main
}
 
void calculateLetterGrades(double arrayPointGrades[],char arrayLetterGrades[], int getStudentCount)// Determines the student's letter grade, loads the array
{ 
char A,B,C,D,F;
int grade;
arrayPointGrades[grade];
if (grade >= 90)
cout << 'A';
else if (grade >= 80)
cout << 'B';
else if (grade >= 70)
cout << 'C';
else if (grade >= 60)
cout << 'D';
else
cout << 'F' << endl;
cin >> arrayLetterGrades[grade];
return 0;
// this statement is used for intial test and debugging
// returns no values to main
} 
 
//void showGradeData(double arrayExamAve[],double arrayLabAve[],char arrayLetterGrades[], double arrayPointGrades[],int getStudentCount )// Prints a table of the student's scores and grades from the arrays
//{ 
// cout << arrayExamAve[eScores] << arrayLabAve[lScores] << arrayLetterGrades[grades] << arrayPointGrades[grades];
// cout <<endl;// this statement is used for intial test and debugging
// // returns no values to main
//}
 
double arrayExamAve(int numStudents,double arrayExamAve[]) // Averages the student's numeric exam grades from the array
{ 
int eScores=0;
int sum=0;
double ave=0;
for (sum = 0; sum <= numStudents; sum++)
{ sum = sum + arrayExamAve[eScores];
ave = sum/numStudents;
}
// this statement is used for intial test and debugging
return ave; // returns average exam score to main
}
 
double arrayLabAve(int numStudents,double arrayLabAve[])// Averages the student's numeric lab grades from the array
{ 
int lScores=0;
int sum=0; 
double aveg=0;
for (sum = 0; sum <= numStudents; sum++)
{ sum = sum + arrayLabAve[lScores];
aveg = sum/numStudents;
}
// this statement is used for intial test and debugging
return aveg; // returns average lab score to main
}
void arrayLetterGrades(char [5], double arrayPointGrades[], int grades)
{
}
//double arrayPointGrades[double grades]
//{
//
// return arrayPointGrades[grades];
//
//} 


I am getting the following errors:

1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(40) : error C2057: expected constant expression
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(40) : error C2466: cannot allocate an array of constant size 0
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(40) : error C2133: 'arrayExam' : unknown size
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(42) : error C2057: expected constant expression
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(42) : error C2466: cannot allocate an array of constant size 0
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(42) : error C2133: 'arrayLab' : unknown size
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(113) : error C2562: 'calculateLetterGrades' : 'void' function returning a value
1> c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(27) : see declaration of 'calculateLetterGrades'
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(131) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(144) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data

any help or advice would be greatly appreciated.
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(40) : error C2057: expected constant expression
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(40) : error C2466: cannot allocate an array of constant size 0
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(40) : error C2133: 'arrayExam' : unknown size

1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(42) : error C2057: expected constant expression
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(42) : error C2466: cannot allocate an array of constant size 0
1>c:\users\livingston\documents\visual studio 2008\projects\source6.cpp(42) : error C2133: 'arrayLab' : unknown size


you made these errors because you tried to make a dynamic array!

line 95,remove your return cause you already declared this function as void!
Last edited on
alright I have corrected the code and have it to where it will ask for the # of students and their lab and exam grades. I just now need it to compile this information and determine a letter grade for each student. Here is my corrected code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#include<iostream>
#include<iomanip>
#define MAX_STUDENTS 20 //sets a default value that can be used for initializing the arrays
using namespace std;
int getStudentCount(); 
void getExamScores(int, double[]); 
void getLabScores(int,double[]); 
void calculatePointGrades(double[], double[], int, double[]);
void calculateLetterGrades(double[],char[], int); 
void showGradeData(double[],double[],char[], double[],int); 
double arrayExamAve(int, double[]); 
double arrayLabAve(int, double[]); 
void arrayPointGrades(char[], double[], int);
char arrayLetterGrades(double[]);

int main() 
{  
        int numStudents = getStudentCount(); 
        cout << "You entered: " << numStudents <<" Students!" <<endl; 
         
        double *arrayExam = new double[numStudents]; 
        getExamScores(numStudents,arrayExam); 
 
         
        double *arrayLab = new double[numStudents]; 
        getLabScores(numStudents,arrayLab); 
         
          
        delete []arrayExam; 
        delete []arrayLab; 
        cout<<"processing has completed in main()"<<endl; 
        cin.ignore(); 
        cin.get(); 
        return 0; 
}
 
int getStudentCount(){
    int numStudents= 20;
    if (numStudents>0 || numStudents<MAX_STUDENTS)
	{
        cout << "Please enter the number of students: ";
		cin >> numStudents;
    }
cout << endl;
return numStudents;
}
 
void getExamScores(int numStudents, double *arrayExam){
    cout << "Please enter the exam grades for each student:"<< endl;
    for (int eScores = 0; eScores <numStudents; eScores++){
        cout<<"student "<<eScores+1<<" grade";
        cin >> arrayExam[eScores];
        cout << endl;
    }
}
 
 
void getLabScores(int numStudents, double *arrayLab){
    cout << "Please enter the lab grades for each student:"<< endl;
    for (int lScores = 0; lScores <numStudents; lScores++){
        cout<<"student "<<lScores+1<<" grade=";
        cin >> arrayLab[lScores];
        cout << endl;// this statement is used for intial test and debugging
    }
}
 
void calculatePointGrades(double *arrayLabAve[], double *arrayExamAve[], int getStudentCount,double arrayPointGrades[] )// Calculates the student's numeric grade, loads the point grade array
{ 
// int grade=0;
// int sum=0;
// int pointGrade=0;
// for (sum = 0; sum <= numStudents; sum++)
// { sum = arrayLabAve[] + arrayExamAve[];
// pointGrade = sum/2;
// cin >> arrayPointGrades[grade];
// cout << endl;
// }
// 
//// this statement is used for intial test and debugging
//return; // returns no values to main
}
 
void calculateLetterGrades(double arrayPointGrades[],char arrayLetterGrades[], int getStudentCount)// Determines the student's letter grade, loads the array
{ 
 int A,B,C,D,F;
int grade;
arrayPointGrades[grade];
if (grade >= 90)
cout << 'A';
else if (grade >= 80)
cout << 'B';
else if (grade >= 70)
cout << 'C';
else if (grade >= 60)
cout << 'D';
else
cout << 'F' << endl;
cin >> arrayLetterGrades[grade];

// this statement is used for intial test and debugging
// returns no values to main
} 
 
//void showGradeData(double arrayExamAve[],double arrayLabAve[],char arrayLetterGrades[], double arrayPointGrades[],int getStudentCount )// Prints a table of the student's scores and grades from the arrays
//{ 
// cout << arrayExamAve[eScores] << arrayLabAve[lScores] << arrayLetterGrades[grades] << arrayPointGrades[grades];
// cout <<endl;// this statement is used for intial test and debugging
// // returns no values to main
//}
 
double arrayExamAve(int numStudents,double arrayExamAve[]) // Averages the student's numeric exam grades from the array
{ 
int eScores=0;
int sum=0;
double ave=0;
for (sum = 0; sum <= numStudents; sum++)
{ sum = sum + arrayExamAve[eScores];
ave = sum/numStudents;
}
// this statement is used for intial test and debugging
return ave; // returns average exam score to main
}
 
double arrayLabAve(int numStudents,double arrayLabAve[])// Averages the student's numeric lab grades from the array
{ 
int lScores=0;
int sum=0; 
double aveg=0;
for (sum = 0; sum <= numStudents; sum++)
{ sum = sum + arrayLabAve[lScores];
aveg = sum/numStudents;
}
// this statement is used for intial test and debugging
return aveg; // returns average lab score to main
}
void arrayLetterGrades(char [5], double arrayPointGrades[], int grades)
{
}
//double arrayPointGrades[double grades]
//{
//
// return arrayPointGrades[grades];
//
//} 


thanks for the help
Topic archived. No new replies allowed.