Hello all, I have been working on a homework assignment that has to build a program for a user to enter student's grades and see the student's average as well as a class avaerage. Besides some cleaning up, organizing, and labeling I am pretty happy with it and it is working. Just one issue not working and I am not sure why. Here is the code:
while (!anotherStudent)
{
cout << "Please enter the Student's Name: ";
getline(cin, studentName);
cout << endl;
studentAverage = studentGrades();
sumOfStudentAverages = sumOfStudentAverages + studentAverage;
cout << "Do you have another Student's grades to record(Yes or No): ";
cin >> answer;
cout << endl;
switch (answer)
{
case 'Y':
case 'y':
cout << studentName << " has ";
if (studentAverage >= 90)
cout << "an \"A\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage >= 80)
cout << "a \"B\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage >= 70)
cout << "a \"C\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage >= 60)
cout << "a \"D\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage < 60)
cout << "a \"F\" Average with a score of " << studentAverage << "." << endl;
anotherStudent = false;
count++;
break;
case 'N':
case 'n':
cout << studentName << " has ";
if (studentAverage >= 90)
cout << "an \"A\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage >= 80)
cout << "a \"B\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage >= 70)
cout << "a \"C\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage >= 60)
cout << "a \"D\" Average with a score of " << studentAverage << "." << endl;
else if (studentAverage < 60)
cout << "a \"F\" Average with a score of " << studentAverage << "." << endl;
anotherStudent = true;
break;
default:
cout << "Please type Y or N: " << endl;
}
}
When you are entering the first student or entering the while loop for the first time, it prompts you to enter the student name. However, when you are prompted to enter another student, if you type y, it prints the prompt for student name but then it immediatley goes to the studentGrades function, and prompts you to enter score 1. It stores a " " in the string for studentName. Let me know if you need to see more code, but I think this is enough. Now I know I have read something about a pause function on the internet but I have not learned that yet in class and I am pretty sure I need to keep it to what I have learned in my last few chapters. Any ideas? Thanks in advance.