Hey. I'm learning c++ and I'm doing a program that requires I make multiple user defined functions. At this point I'm working with my first function where I have to make a 2d array, but I keep getting a segmentation fault (core dumped) message. Here is the code:
You're getting the seg fault probably because in getGrades(), you only specify an int for the parameter, it should be:
double getGrades( int students )
You should be passing in the value that the user typed in the main function. Since students is not initialized in getGrades, the value of students is probably some wacky value or even negative! So, in the getGrades function, take out int students under int count1, count;
Anywhere you have a stack variable, you should initialize it. Even though in the getGrades function you initialize count1 and count in your "for" loops, you should get into the habit of initializing variables when you declare them.
thanks, that fixed the problem and got me a ways further. Now I just have a question. In my second for loop, I want to set it so I calculate an average for each student and finally a class average. How could I do that?
In your getGrades function you have collected all the information that is needed. You will need another function that:
1 2 3 4 5 6 7 8 9 10
for each student:
sum up each test (Hint: Another loop)
this student's average = sum / tests
add this student's average to the class average
class average = class average / tests