Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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.

#include const int arrSize 200; //declaring array size to be 200 void mostFrequentLetter(char*, int); // Function mostFrequentLetter definition int main using namespace std; char sentence arrSizel;// Declaring array named sentence which will store the input from the user to process cin.getline(sentence, arrSize); //taking input from console mostFrequentLetter(sentence, arrSize); // funciton mostFrequentLetter call return 0 void mostFrequentLetter(char letters, int len) // function body of mostFrequentLetter using namespace std; char character; int m = 0; int maximum = 0, index=0; int n, count;

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