how do i get my code to have output to say - most fequent letter: t, 6 times ,la
ID: 3587526 • Letter: H
Question
how do i get my code to have output to say - most fequent letter: t, 6 times ,last seen at index 43.
when my input is- the time is always right to do what is right.
Explanation / Answer
//changed the logic inside function,,so just posing that function and you can find my changes with keyword CheggEA
void mostFrequentLetter(char *letters, int len)
{
char character;
int m = 0;
int maximum = 0, index = 0;
int n, count;
while (letters[m] != '')
{
m++;
}
const char *start;
const char *last = letters + m;
for (start = letters; start != last; start++)
{
n = 0;
count = 0;
while (letters[n])
{
if (*start == letters[n] && *start!=32)
{
//last see index is assigned here,ChegEA
index = n;
count++;
}
n++;
}
if (count >= maximum)
{
maximum = count;
character = *start;
//chegEA commented below line
//index = -n;
}
}
//commented out belowe line,CheggEA
//cout << "Most frequent letter: " << character << "," << maximum << "times last seen at index " << n << endl;
//changed outputting n to index ,CheggEA
cout << "Most frequent letter: " << character << "," << maximum << "times last seen at index " << index << endl;
}
-----------------------------------------------------------------
//output same as given
the time is always right to do what is right
Most frequent letter: t,6times last seen at index 43
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.