0

First off, If there's any missing information, or you need to know more, please let me know. I'm not an experienced programmer by any means, and this mostly a project I'm working on for a university course.

This is my function definition:

void DispReport(string names[], int IDs[], int grades[][8], int numStudents, int numClasswork, int numQuizzes) {

The job of this function is to display a full table of student names with their ID numbers and grades. At the start, the function will display headers of "Name", "ID", and so on. Then display a continuous line of hyphens as a border underneath. After that it will start extracting and displaying the names, IDs and grades. This is the loop involved (I realize there's a lot of repetitiveness, sorry):

int Qmin, Qmax, CWmin, CWmax, Total;
    for(i = 0; i < numStudents; i++){
        cout << i+1 << ".";
        cout << setw(11) << names[i];
        cout << setw(11) << IDs[i];
        //Display Quizzes, and Qmin ,Qmax, and Qavg
        for(j = 0; j < numQuizzes; j++){
            cout << setw(11) << grades[i][j];
            if(grades[i][j] < grades[i][j+1])
                Qmin = grades[i][j];
            else
                Qmax = grades[i][j];
        };
        cout << setw(11) << Qmin;
        cout << setw(11) << Qmax;
        cout << setw(11) << (Qmin + Qmax)/2;
        //Display Classwork, and CWmin, CWmax, and CWavg
        for(j = numQuizzes; j < (numQuizzes + numClasswork); j++){
            cout << setw(11) << grades[i][j];
            if(grades[i][j] < grades[i][j+1])
                CWmin = grades[i][j];
            else
                CWmax = grades[i][j];
        };
        cout << setw(11) << CWmin;
        cout << setw(11) << CWmax;
        cout << setw(11) << (CWmin + CWmax)/2;
    };

Running this loop results in nothing, however. It runs once, outputting the very first line, "1.", pauses for a second, then the program terminates. Nothing. I checked to ensure that the function had actually receive the arrays I passed to it, through cout << names[different indexes to check different names] and it was all there. The loop however, wouldn't display them, and I'm not getting any error messages. Any ideas?

  • 2
    Take a look at [What is a debugger and how can it help me diagnose problems?](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems) – 273K May 06 '20 at 17:06
  • Undoubtedly your program is crashing on something in the loop (which does look a bit weird I have to say). Nothing in your loop ever outputs a `\n` which is probably why you don't see more output. Try adding `<< flush` to the end of each `cout`, e,g, `cout << setw(11) << grades[i][j] << flush;`. This will force the output to appear immediately and will give you a better idea of where your program is going wrong. But an experienced programmer would be using a debugger at this point. Maybe time to learn? – john May 06 '20 at 17:42
  • Thank you very much. I'll try using flush and \n to find the issue. I may be a beginner, but I'm not unwilling to learn, and of course I'll look into debuggers. Thanks, once again – user13484657 May 06 '20 at 18:10
  • I know this is an old post, which is why I'd like to ask you to consider either writing up the solution you found (see [answer]), or deleting your question. – starball Nov 24 '22 at 03:35

0 Answers0