I'm to write a program using function to ask the user to enter their grade in a class, then determine the GPA. All the while keeping track of the number of people who have passed and failed.
I cannot seem to get the while loop to accept multiple entry's until ctrl z is entered. I think I may have the (!cin.eof()) in the wrong place. Any help would be greatly appreciated.
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void showTitle()
{
cout << "Student Grade Summary" << endl;
cout << "Enter Grades A, B, C, D, F or Ctrl Z when done" << endl;
}
char getValidGrade()
{
char grade;
int numstudentpass , numstudentfail;
cout << "Enter a grade: ";
cin >> grade;
grade=toupper(grade);
This isn't working correctly: while ((!cin.eof()) && grade !='A' && grade != 'B' && grade != 'C' && grade != 'D' && grade !='F')
try something like while (!cin.eof()) && (grade == 'A' || grade == 'B'...))
Then you put the letter to upper, so your if statement never calculates 'f'. You increase the pass/fail count, but this is a local variable and lost when the function ends.
But the main thing is that you return grade while in the loop, so the loop will never loop.
And, grade is never initialized, try a do while loop.