potato4610 0 Newbie Poster

How can I get the respondent to terminate my survey before all respondents have entered? That respondent may enter a specific number of out of range responses in a row.

Below is my code:

#include <iostream>
#include <cctype>
using namespace std;

const int STUDENTS  = 10;                    // students entering a grade
const int GRADETYPES  = 6;                   // includes illegal grade E

void CountGrades();

int main()
{
    cout << "Please input your grade between A - F: ";
    CountGrades();
}

void CountGrades()
{
    int loopCount, grades[GRADETYPES];
    char grade;
    
    for (loopCount = 0; loopCount < GRADETYPES; ++loopCount)      // a way to initialize array to 0s
        grades[loopCount] = 0;
    for (loopCount = 0; loopCount < STUDENTS;)
    {
        cout << " Enter a letter grade for person # " << loopCount + 1 << ": ";
        cin >> grade;
        grade = char (toupper(grade));
        if (grade >= 'A' && grade <= 'F' && grade!= 'E' )         // convert grade to array index
            grade -= 'A' ;
        else
        {
            cerr << grade << " is not a legal grade\n";
            continue ;                                            // ask for same student's grade again
        }
        ++grades[grade];                                          // increment grade count
        ++loopCount;                                              // not in for because of continue
    }
    for (loopCount = 0; loopCount < GRADETYPES; ++loopCount)
        if (loopCount != 'E' - 'A' )                              // output legal grades
            cout << grades[loopCount] << ' ' << char (loopCount + 'A' ) << '\n' ;
}