Alright I read it and it did help alot. I understand the way it works far more now then I did before. I'm attempting to fix the code. Still running into a few problems though.
Haven't really done to much to the code yet but I'm still kind of sketchy:
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
|
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int const MAXSTUDENTS = 100;
int getStudentCount();
int noofstu;
int getExamScores();
int ExamScores[];
int num;
int getLabScores();
int LabScores[];
int i;
int getStudentCount()
{
cout << "Calculating Students Grades" << endl;
cout << "\nHow many students grades would you like to enter today?\n" << endl;
cin >> noofstu;
return 0;
}
int getExamScores()
{
if (noofstu == 0)
{
cout << "You have entered no students, try again" << endl;
}
else
{
for (num=0; num < noofstu; num++)
{
int n = num + 1;
cout << "\nEnter Exam Score(s) for student "<< n++ << endl;
cin >> ExamScores[num];
}
cout << "You've entered: ";
for (num=0; num < noofstu; num++)
cout << ExamScores[num]<< ", ";
cout << "\n" << endl;
int * Examscores;
Examscores = new int;
Examscores = &ExamScores[num];
}
return 0;
}
int getLabScores()
{
for (num =0; num < noofstu; num++)
{
int n = num + 1;
cout << "\nEnter Lab Score(s) for student "<< n++ << endl;
cin >> LabScores[num];
}
cout<< "You Entered:";
for (num=0; num < noofstu; num++)
cout << LabScores[num]<< ", ";
int * Labscores;
Labscores = new int;
Labscores = &LabScores[num];
return 0;
}
int calculatePointGrades(Examscores, Labscores)
{
int * Pointgrades;
int sum = 0;
for (int i=0; i<noofstu; i++)
{
Pointgrades[i] = *Examscores[i]+ *Labscores[i];
}
return 0;
}
int main ()
{ //Open main
getStudentCount();
getExamScores();
getLabScores();
cin.ignore(2);
return 0;
} // Close main
|
First you say I need to declare Examscores and Labscores, and I think I understand why, but not how to go about doing it correctly. I understand when the return statement executes it deletes the pointer. What I don't know is where to declare the pointer again.
I think I need to declare:
getLabScores * Labscores = new &LabScores[num];
or just
* Labscores = new &LabScores[num];
or should I make the pointer a constant?
Whenever I declare them out of a function they get syntax errors until all that's left is the pointer = new. Kinda stumped.
you also say the three functions getExamScores(), getLabScores() and calculatePointGrades() should return a pointer to an int array, not an int. I think I took care of this because it was going to [noofstudents] orginally. Correct me if I'm wrong.
I think I'm understanding better but the execution is still off.
Also getting error C2448: 'calculatePointGrades' : function-style initializer appears to be a function definition. hmmmm