I keep getting (exit status -1) when running my c++ project

Question:
I’m working on a school project and cannot figure out how to fix my program so I don’t get exit status -1.

Current behavior:
The program asks for a student’s info, and then has you fill in what courses they are taking. In main, it asks for user input of 3 test grades in each course by using a nested for loop. The problem is, regardless of the number of courses, Once i enter the last test grade for the last course I always get exit status -1.

Desired behavior
The after where the exit status -1 keeps happening, the for loop is supposed to stop, and then move on to testing certain functions in my classes. All I really need is for the program to get out of the for loops without exit status -1.
Repl link:
https://replit.com/@HaydenKom/Project-1-1

code snippet

At a glance: in the Student::setCourses method, you seem to have hardcoded 10 for the upper bound of i instead of taking into account how many courses are passed in, which can currently be less than 10, causing it to read past the buffer for c. Instead of 10, try (sizeof(c)/sizeof(*c)).
Also you probably want to validate the input when taking the number of courses so you can’t have any more than 10 courses.

1 Like