I have a c++ program I've been working on, it displays student grades from a sequential access file, then uses the same file to calculate and display each students gpa. after calling displayGpa() it says "Run-Time Check Failure #2 - Stack around the variable 'gpa' was corrupted."
Here is the .cpp file giving me trouble:
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "sRecords.h"
using namespace std;
void sRecords::displayGpa()
{
    string firstName, lastName;
    string grade[4];
    double gpa[4];
    double finalGpa[4];
    ifstream inputFile;
    inputFile.open("studentRecords.txt");
    while (inputFile)
    {
        inputFile >> firstName >> lastName;
        int x = 0;
        while (x <=3)
        {
            inputFile >> grade[x];
            if (grade[x] == "A")
            {
                gpa[x] = 4.00;
            }
            else if (grade[x] == "A-")
            {
                gpa[x] = 3.70;
            }
            else if (grade[x] == "B+")
            {
                gpa[x] = 3.33;
            }
            else if (grade[x] == "B")
            {
                gpa[x] = 3.00;
            }
            else if (grade[x] == "B-")
            {
                gpa[x] = 2.70;
            }
            else if (grade[x] == "C+")
            {
                gpa[x] = 2.30;
            }
            else if (grade[x] == "C")
            {
                gpa[x] = 2.00;
            }
            else if (grade[x] == "C-")
            {
                gpa[x] = 1.70;
            }
            else if (grade[x] == "D+")
            {
                gpa[x] = 1.30;
            }
            else if (grade[x] == "D")
            {
                gpa[x] = 1.00;
            }
            else if (grade[x] == "D-")
            {
                gpa[x] = .70;
            }
            else
            {
                gpa[x] = 0.00;
            }
        x++;
        }
        finalGpa[x] = (gpa[0] + gpa[1] + gpa[2] + gpa[3]) / 4;
        cout << firstName << " " << lastName << " " << finalGpa[x] << endl;
    }
    inputFile.close();
}
void sRecords::displayHeader()
{
    cout << "\t-------------------------------" << endl;
    cout << "\t\tSTUDENT RECORDS" << endl;
    cout << "\t-------------------------------" << endl << endl;
}
void sRecords::printRecords()
{
    ifstream inputFile;
    inputFile.open("studentRecords.txt");
    string string1, string2, string3, string4, string5, string6;
    cout << setw(12) << left << "FIRST NAME" << setw(11) << left << "LAST NAME";
    cout << setw(9) << left << "ENGLISH" << left << setw(6) << "MATH";
    cout << setw(9) << left << "SCIENCE" << left << setw(12) << "CHEMISTRY" << endl << endl;
    while (inputFile)
    {
        inputFile >> string1 >> string2 >> string3 >> string4 >> string5 >> string6;
        cout << setw(12) << left << string1 << setw (11) << left << string2; 
        cout << setw(9) << left << string3 << setw(6) << left << string4; 
        cout << setw(9) << left << string5 << setw(12) << left << string6 << endl;
    }
    cout << endl;
    inputFile.close();
}
 
    