#include <stdio.h>

struct countyTotals
{
    int totalCorkCodes;
    int totalDublinCodes;
    int totalGalwayCodes;
    int totalLimerickCodes;
    int totalTiperaryCodes;
    int totalWaterfordCodes;
    int totalInvalidCountryCodes;
};
   
// add function block comments
struct countyTotals freqOfIrishCounties(char countyArrayList[], int size)
{

    struct countyTotals myCountyTotals = {0,0,0,0,0,0,0};  // holds the country counts
                                                           // and initializes them to zero

    // Review each of the county codes in the array
    for(int i = 0; i < size; i++)
    {
        
        switch (countyArrayList[i]) //Structure variable countyArrayList
        {

            case 'C': // Cork uppercase and lowercase accepted
            case 'c':
                myCountyTotals.totalCorkCodes++; // add count if in category
                break; //signify end of cases

            case 'D': // Dublin uppercase and lowercase accepted
            case 'd':
                myCountyTotals.totalDublinCodes++; // add count if in category
                break;

            case 'G': // Galway uppercase and lowercase accepted
            case 'g':
                myCountyTotals.totalGalwayCodes++; // add count if in category
                break; 

            case 'L': // Limerick uppercase and lowercase accepted
            case 'l':
                myCountyTotals.totalLimerickCodes++; // add count if in category
                break;

            case 'T': // Tipperary uppercase and lowercase accepted
            case 't':
                myCountyTotals.totalTiperaryCodes++; // add count if in category
                break;

            case 'W': // Waterford uppercase and lowercase accepted
            case 'w':
                myCountyTotals.totalWaterfordCodes++; // add count if in category
                break;

            default: // Invalid country codes
                myCountyTotals.totalInvalidCountryCodes++; // add count if in category
                break;

        } // switch
    } // for

    return (myCountyTotals);

} // freqOfIrishCounties

int main(void) {
    char counties[] = {'c', 'C', 'd', 'D', 'g', 'G', 'L', 'l', 'T', 't', 'W', 'w', 'r', 'j', 'm'};
    int size = sizeof(counties) / sizeof(counties[0]);  // define size of array

    struct countyTotals totals = freqOfIrishCounties(counties, size); // Store results from countytotals

    printf("Cork codes: %d\n", totals.totalCorkCodes); //Print Cork total stored
    printf("Dublin codes : %d\n", totals.totalDublinCodes); //Print Dublin total stored
    printf("Galway codes : %d\n", totals.totalGalwayCodes); //Print Galway total stored
    printf("Limerick codes : %d\n", totals.totalLimerickCodes); //Print Limerick total stored
    printf("Tipperary codes : %d\n", totals.totalTiperaryCodes); //Print Tipperary total stored
    printf("Waterford codes : %d\n", totals.totalWaterfordCodes); //Print Waterford total stored
    printf("Invalid codes : %d\n", totals.totalInvalidCountryCodes); //Print Invalid total stored

    return 0;
}