RobBrown 29 Light Poster

Hello, I am having problems debugging a program that was written to decrypt a caesar cipher. The program reads in a text file character by character into an array, determines which character appears most and declares it 'e', then proceeds to determine the "shift" to employ. Currently i have the program to read in the file to an counter array, display the array, and display the decimal equivilant of the most common letter. this is just done for debugging purposes so i can see where i am going wrong. However, i am having a hard time figuring out how to fix my error. For debugging purposes i have a for loop that is set to only display the array counters for a - g which i have used to determined the array is coming out correctly so I have narrowed it down to the function which gets the most common letter and shifts it (this part is just set to show the most common character right now). For testing purposes i am using a text file that just contains 17 F's in a row, and for some reason the function is declaring the most common character as the decimal value that should correspond to 'r'. As far as i can tell the loop i have to compare the counter array should be working but it is still givng wrong output. I have posted code and the output below for the program i have set to debug. Any help would be much appreciated.

Input the location of the file you want to decode: c://debugtest.txt
0
0
0
0
0
17
0
0
Current ASCII offset is: 114


End of message.

Press enter to quit.

code:

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>

int letterCounter[25] = {0};
void counter(char ch);
int funcOffset();

using namespace std;

int main() {
    string fileLocation;
    ifstream textFile;
    char character;
    int characterDecodedInt;
    char characterDecodedChar;
    string finalMessage;
    int offset;
    string quit;
    
    //Ask the user to give the location of the file, and open it.
    cout << "Input the location of the file you want to decode: ";
    getline(cin, fileLocation);
    textFile.open(fileLocation.c_str());
    
    //Check if the file opened successfully, and prompt them to go again if it didn't.
    while (!(textFile.is_open())) {
        cout << "Invalid file location. Please try again: ";
        getline(cin, fileLocation);
        textFile.open(fileLocation.c_str());
    }
    
    //Adds up the total number of times each letter appeared in the file.
    while (textFile.peek() != EOF) {
        textFile.get(character);
        counter(character);
    }

    //displays contents of array
    
    for (int i = 0; i < 8; i++) {
        cout << letterCounter[i] << endl;
    }
    
    // determines offset
    
    offset = funcOffset();
    cout << "Current ASCII offset is: " << offset << endl;
             
    cout << "\n\nEnd of message.";
    
    cout << endl << endl;
    cout << "Press enter to quit.";
    getline(cin, quit);
    return 0;
    
}

/*The purpose of the following function is to count up the number of times each
letter appears in the text file.*/
void counter(char ch) {
    switch(ch) {
        case 'a':
        case 'A':
            letterCounter[0]++;
            break;
        case 'b':
        case 'B':
            letterCounter[1]++;
            break;
        case 'c':
        case 'C':
            letterCounter[2]++;
            break;
        case 'd':
        case 'D':
            letterCounter[3]++;
            break;
        case 'e':
        case 'E':
            letterCounter[4]++;
            break;
        case 'f':
        case 'F':
            letterCounter[5]++;
            break;
        case 'g':
        case 'G':
            letterCounter[6]++;
            break;
        case 'h':
        case 'H':
            letterCounter[7]++;
            break;
        case 'i':
        case 'I':
            letterCounter[8]++;
            break;
        case 'j':
        case 'J':
            letterCounter[9]++;
            break;
        case 'k':
        case 'K':
            letterCounter[10]++;
            break;
        case 'l':
        case 'L':
            letterCounter[11]++;
            break;
        case 'm':
        case 'M':
            letterCounter[12]++;
            break;
        case 'n':
        case 'N':
            letterCounter[13]++;
            break;
        case 'o':
        case 'O':
            letterCounter[14]++;
            break;
        case 'p':
        case 'P':
            letterCounter[15]++;
            break;
        case 'q':
        case 'Q':
            letterCounter[16]++;
            break;
        case 'r':
        case 'R':
            letterCounter[17]++;
            break;
        case 's':
        case 'S':
            letterCounter[18]++;
            break;
        case 't':
        case 'T':
            letterCounter[19]++;
            break;
        case 'u':
        case 'U':
            letterCounter[20]++;
            break;
        case 'v':
        case 'V':
            letterCounter[21]++;
            break;
        case 'w':
        case 'W':
            letterCounter[22]++;
            break;
        case 'x':
        case 'X':
            letterCounter[23]++;
            break;
        case 'y':
        case 'Y':
            letterCounter[24]++;
            break;
        case 'z':
        case 'Z':
            letterCounter[25]++;
            break;
        default:
            break;
    }
}

/*The purpose of this function is to determine which letter appeared most often,
identify it as E, and then determine how much the offset should be when decoding*/
int funcOffset() {
    int i;
    int highestNum = letterCounter[0];
    char letter;
    
    for (i = 0; i < 26; i++) {
        if (letterCounter[i] < letterCounter[i+1]) {
            highestNum = letterCounter[i+1];
        }
        else if (letterCounter[i] > letterCounter[i+1]) {
            highestNum = letterCounter[i];
        }
    }
    switch (highestNum) {
        case 0:
            letter = 'a';
            break;
        case 1:
            letter = 'b';
            break;
        case 2:
            letter = 'c';
            break;
        case 3:
            letter = 'd';
            break;
        case 4:
            letter = 'e';
            break;
        case 5:
            letter = 'f';
            break;
        case 6:
            letter = 'g';
            break;
        case 7:
            letter = 'h';
            break;
        case 8:
            letter = 'i';
            break;
        case 9:
            letter = 'j';
            break;
        case 10:
            letter = 'k';
            break;
        case 11:
            letter = 'l';
            break;
        case 12:
            letter = 'm';
            break;
        case 13:
            letter = 'n';
            break;
        case 14:
            letter = 'o';
            break;
        case 15:
            letter = 'p';
            break;
        case 16:
            letter = 'q';
            break;
        case 17:
            letter = 'r';
            break;
        case 18:
            letter = 's';
            break;
        case 19:
            letter = 't';
            break;
        case 20:
            letter = 'u';
            break;
        case 21:
            letter = 'v';
            break;
        case 22:
            letter = 'w';
            break;
        case 23:
            letter = 'x';
            break;
        case 24:
            letter = 'y';
            break;
        case 25:
            letter = 'z';
            break;
    }
    //This will find the difference in ASCII code between 'e' and our mystery
    //letter, determining what the "shift" is.
    return(static_cast<int>(letter));
}