GRADE ARRAY_NEED ADVICE FAST

Hello. I am absolutely brandnew in c++. I am currently in the middle of my Computer Engineering class (mainly for the electronics part) but nevertheless I have to study a bit of coding. I have a project I've been working on for class. I was wondering if any of you could point me in the right direction. I know I DEFINITELY have issues with calling functions, no doubt. I appreciate your help!

// Week 6 Lab
//
// The following framework support the basic assignment requirements
// for the code structure.
//
// The framework needs to be updated to include all of the
// necessary processing and to address all of the requirements
//
/************************************************************************
* Course:
*
* Assignment: Week 6 Grade Arrays
*
* Write a program that asks the user how many students
* to process, then reads in the scores for two items, u
* an exam score and lab average, for that many students,
* then calculates and displays a table of the students’
* grade information.
*
* Filename: gradeArray.cpp
*
* Input: Numeric menu items from the keyboard
*
* Output: Table of entered scores and calculated grades
*
**************************************************************************/
#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

void main() // controls program sequence (can be moved back to the top once the function parameters are defined.)
{
cout<<"processing has started in main()"<<endl;// this statement is used for intial test and debugging

int numStudents = getStudentCount();

getStudentCount(numStudents);
getExamScores(numStudents,arrayExamAve[eScores]);
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;
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 arrayExamAve[])// Gets exam scores from user, loads the array
{
int eScores=0;
cout << "Please enter the exam grades for each student:";

for (eScores = 0; eScores <= numStudents; eScores++)
{
cin >> arrayExamAve[eScores];
cout << endl;// this statement is used for intial test and debugging
return; // returns no values to main
}
}



void getLabScores(int numStudents,double arrayLabAve[])// Gets lab scores from user, loads the array
{
int lScores=0;
cout<<"Please enter the lab scores for each student:";

for (lScores = 0; lScores <= numStudents; lScores++)
{
cin >> arrayLabAve[lScores];
cout << endl;// this statement is used for intial test and debugging
return; // returns no values to main
}
}


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];

// 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;
int 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;
int 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];

}
Last edited on
Read these, try to finish it, and if you still have problems, go ahead and post the errors/code.

http://www.cplusplus.com/doc/tutorial/functions/
http://www.cplusplus.com/doc/tutorial/functions2/
http://www.cplusplus.com/doc/tutorial/arrays/

Oh, and you need int main().
Last edited on
As in, not void main. Because void main is nonstandard and wrong. Always.
Here are the error codes. They are more than I remembered but I think the initial way I had it was wrong anyways. I will re-read those chapters on the tutorials page. I know my issues are with the function structure and how i'm calling them. I appreciate your help!


ERROR CODES:

1>------ Build started: Project: OAKLEY_lab06, Configuration: Debug Win32 ------
1>Compiling...
1>gradeArray.cpp
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : error C2144: syntax error : 'char' should be preceded by ']'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : error C2144: syntax error : 'char' should be preceded by ';'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : error C2182: 'arrayPointGrades' : illegal use of type 'void'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : warning C4091: '' : ignored on left of 'char' when no variable is declared
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : error C2143: syntax error : missing ';' before '['
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : error C3409: empty attribute block is not allowed
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : error C2059: syntax error : ','
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : error C2144: syntax error : 'double' should be preceded by ']'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : error C2144: syntax error : 'double' should be preceded by ';'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : warning C4091: '' : ignored on left of 'double' when no variable is declared
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : error C2143: syntax error : missing ';' before '['
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : error C3409: empty attribute block is not allowed
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : error C2059: syntax error : ']'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(56) : error C2660: 'getStudentCount' : function does not take 1 arguments
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(57) : error C2065: 'eScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(58) : error C2065: 'lScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(59) : error C2065: 'lScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(59) : error C2065: 'eScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(59) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(60) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(60) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(61) : error C2065: 'eScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(61) : error C2065: 'lScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(61) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(61) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(112) : error C2065: 'numStudents' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(113) : error C2059: syntax error : ']'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(151) : error C2065: 'eScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(151) : error C2065: 'lScores' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(151) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(151) : error C2065: 'grades' : undeclared identifier
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(163) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(177) : warning C4244: '=' : conversion from 'double' to 'int', possible loss of data
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(185) : error C2365: 'arrayLetterGrades' : redefinition; previous definition was 'data variable'
1> c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(43) : see declaration of 'arrayLetterGrades'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(189) : error C2144: syntax error : 'double' should be preceded by ']'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(189) : error C2144: syntax error : 'double' should be preceded by ';'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(189) : error C2371: 'arrayPointGrades' : redefinition; different basic types
1> c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(42) : see declaration of 'arrayPointGrades'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(189) : error C2143: syntax error : missing ';' before ']'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(190) : error C2143: syntax error : missing ';' before '{'
1>c:\users\joshua\documents\visual studio 2008\projects\oakley_lab06\oakley_lab06\gradearray.cpp(190) : error C2447: '{' : missing function header (old-style formal list?)
1>Build log was saved at "file://c:\Users\Joshua\Documents\Visual Studio 2008\Projects\OAKLEY_lab06\OAKLEY_lab06\Debug\BuildLog.htm"
1>OAKLEY_lab06 - 36 error(s), 4 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

okay
I have fixed quite a bit and now the error code i'm getting is...

error C2664: 'getExamScores' : cannot convert parameter 1 from 'int (__cdecl *)(void)' to 'int'

int getExamScores(int, double[]);- this is my definition declaration before main()
int getExamScores(int numStudents, double arrayExamAve[])- this is the function itself
getExamScores(getStudentCount,arrayExamAve);this is the function being called (line 57)

thanks

getExamScores(getStudentCount(),arrayExamAve);
or better getExamScores(numStudents,arrayExamAve);

getStudentCount is a function. In your case you don't want to pass this in getExamScores. What you want to pass is the number of students. So, first call
numStudents=getStudentCount();
and then
getExamScores(numStudents,arrayExamAve);

and when you post your code use code tags like this:
[c o d e]...your code here...[/ c o d e]
(without the spaces between the characters in "c o d e" and "/ c o d e")
Last edited on
Hi I am having a similar problem my code is:
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 would be greatly appreciated
Topic archived. No new replies allowed.