C++ Question "timeout: the monitored command dumped core" [closed]

  c++, function, loops

Hello I am making this question because on the for loop "for (grade = 0; grade != -1; numbOfTests++)" or in the getGrade function there seems to be an error if you enter the integer "-1" in the cin input first. More so it gives the "timeout: the monitored command dumped core" error. What is causing this? I looked up on google but the errors dont seem to be the same as mine. Id appreciate the help, my code is below.

#include <iostream>

const int EXTRA_CREDIT = 3;

void displayIntro();
int getGrade();
int finalAverage(int, int);

int main()
{
  int grade, sum, numbOfTests, average;
  
  displayIntro();
  
  numbOfTests = -1;
  sum = 0;
  
  for (grade = 0; grade != -1; numbOfTests++)
  {
    grade = getGrade();
    sum = sum + grade;
  } 
  
  sum++;
  average = finalAverage(sum, numbOfTests);
  
  std::cout << "Exam average, including extra credit, "
            << "is: " << average << std::endl;
  
  return 0;
}

void displayIntro()
{
  std::cout << "This program will calculate the average(%) of "
            << "exam grades." << std::endl;
  std::cout << "It will also add extra credit points to the exam "
            << "average given the course difficulty." << std::endl;
  std::cout << "Enter all of the grades for one student. Type (-1)" 
            << " when finished with that student." << std::endl;
  std::cout << "If you have additional students, you will be prompted"
            << " to repeat the program at the end." << std::endl;
}

int getGrade()
{
  int userGrade = 0;
  
  std::cout << "Enter an exam grade (type -1 to quit):" << std::endl;
  std::cin  >> userGrade;
    
  return userGrade;
}

int finalAverage(int runningSum, int counter)
{
  int final;
  
  final = (runningSum / counter) + EXTRA_CREDIT;
  
  return final;
}

Source: Windows Questions C++

LEAVE A COMMENT