I am having some trouble getting a C++ logic loop working. From testing, I believe it is a error in the Grades() function loop.
Basically the program is supposed to get the Names and Test Scores, which it appears to do, but the program exits right after that and I am not sure why. Just wanting to see if anyone else noticed an error in the function that could be causing the program to terminate prematurely.
// Grades
void Grades(char names[][length], double grades[][4])
{
for(int i = 0; i < amount; i++)
{
cout << "Name: ";
cin.ignore();
cin.getline(names[i],length, '\n');
cout << "Test Scores: ";
for(int k = 0; k < 4; k++)
{
int num = 0;
while(!(cin >> num) ||
num < 0 ||
num > 100 )
{
cout << "invalid entry." << endl;
}
grades[i][k] = num;
}
}
}
What compiler/operating system are you using?
Sometimes it’s necessary to add a
system("pause");call before you return from main. This is often true if you’re compiling from an IDE than runs the program directly. You could avoid the problem by running it directly from the command line/bash/etc.