Display the most frequent character

Hello guys!
im trying to this program, where you enter some characters and once you have completed that part the program will show you whats the most frequent letter, if the characters are all the same or if you have enter the characters only once.

Here is my code but its only showing me that the characters are always the same no matter what.

Last edited on
closed account (48T7M4Gy)
Your model for what you want could be improved and made a lot simpler by considering this way of doing it:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

using namespace std;

void checkAlphaInput(int [], int);
void sortingArray(int [], int);
int printMostFrequent(int [],int);

int main(){
    
    const int MAXALPHA = 26;
    int alphas[MAXALPHA]{0};
    
    checkAlphaInput(alphas, MAXALPHA);
    sortingArray(alphas, MAXALPHA);
    printMostFrequent(alphas, MAXALPHA);
    
    return 0;
}


Here alphas is just an array of ints where each element of the array is the count of input chars corresponding to each of the 26 characters of the alphabet.

So if you type in the character 'c' for example, and knowing that this corresponds to element 'c'-'a' = 2 on the ASCII scale, element alphas[2] can be updated by adding 1 (+=1, or alphas[2]++).

The sorting function won't be required and the highest frequency can be worked out by processing the alphas array.

Topic archived. No new replies allowed.