Most frequent element help

Hello all! Beginner programmer here. I'm trying to write a program to output the most frequent character in the string but the output isn't working properly... Please help point out my problem! I'm lost!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
using namespace std;

char charArray[50];
int i, arraySize;

char getMostFrequentChar(char charArray[], int arraySize) {
	char max = charArray[0];
	arraySize = strlen(charArray);
	for (i = 0; i < arraySize; i++) {
		if (charArray[i] > max) {
			max = charArray[i];
		}
	}
	cout << "The most frequent character is: " << max << "\n";
	return 0;
}

int main() {

	cout << "Enter a word: "; 
	cin >> charArray;

	getMostFrequentChar(charArray, arraySize);

	system("pause");
	return 0;
}
Last edited on
try to also output the frequency of the character, perhaps you'll notice then.
Topic archived. No new replies allowed.