A program to calculate students grades.the user
enter number of subjects and number of students then create 2D array of type Double for them.the user enter the grade of each student for each subject then
create a function which takes the 2D array of student grades and return 2D array of type String which contains the GPA of each subject for each
student
Starting at line 76, you start to allocate memory to Matrix but you don't continue to do so in a for-loop. Remember you have to allocate memory for the columns as well
1 2 3 4 5 6 7 8 9 10
Matrix= newdouble*[studentsNum]; //Allocate Memory
for(int i=1;i<=studentsNum;i++)
{
for(int j=1;j<=subjectsNum;j++)
{
cout<<"Enter grade of Subject#"<<j<<" for Student#"<<i<<": ";
cin>>grade;
}
}
It might not be the only problem, but that's a start.
#include <iostream>
usingnamespace std;
int main()
{
double **Matrix;
// allocate a 2d array, below example
// is like allocating Matrix[2][3]
Matrix = newdouble*[3];
for (int i = 0; i < 3; ++i)
Matrix[i] = newdouble[2];
// ..... do stuff
// release memory
for (int i = 0; i < 3; ++i)
delete[] Matrix[i];
delete[] Matrix;
return 0;
}
Read above, you haven't allocated your 2D array correctly - as PrivateRyan stated it would be a good start to get that corrected first and go from there.
yeah ,I did that and I've already corrected what you all said and allocate 2D array correctly but still the program stopped working unexpectedly
Thanks in advance for your reply...
I don't know where or what failed this code so I didn't specify as I don't know where is the error
yes , I've debugged the code but I don't reach a useful result...
Thank You again for helping me and sorry if I waste your time...
Well i'm off to sleep now but what I would suggest is for you to re-post your updated code where you fixed the allocation of the 2d arrays then if someone comes across your post they may be able to help you.