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

#include<iostream> how do i fix my code ? #include<string> using namespace std;

ID: 3887877 • Letter: #

Question

#include<iostream>

how do i fix my code ?
#include<string>
using namespace std;

int main(){
const int numberOfLetters = 25;
const int size = 200;

char sentence[size],ch;

int i,j,maximum, ind=0, counts[numberOfLettersl

cout<<"Enter the phrase: ";




cin.getline(sentence, 200);

for (int i = 0; i < numberOfLetters; i++){

counts[i] = 0;

}

for (int i = 0; i < numberOfLetters; i++){

counts[sentence[i] - 'a']++;

}

cout<<endl;

maximum=0;

for(i=0;i<numberOfLetters;i++){

if(maximum<=counts[i]){

maximum=counts[i];

ch=char(i + 'a');

}

}

for(i=0;i<size;i++){

if(sentence[i]==ch){

ind=i;

}

}

cout<<"Most frequent letter: "<<ch<<", "<<maximum <<" times, last seen at index "<<ind;

}

The task s find the most common letter in a string You will have to ask the user to type something (you can assume all leter and Then you should prnt the letter that was the most frequent, and then the appeared enter Example input and outputs e Use a char array to store the input phrase, I suggest making it 200 characters long , Keep in mind that there are exactly 25 lowercase letters, between ascia 122 (2) Remember what we covered in class, arrays and variables won't be initialized to themselves To print out a number back as a character, for example to print out 97 as a CAST it as a character, by putting a (char) in front of the variable For etample this . int tom-98; cout sentence; that you are familiar with. The effect is the variable sentence will now hold that test just stop after

Explanation / Answer

#include<iostream>
#include<string>
using namespace std;

int main(){

const int numberOfLetters = 25;

const int size = 200;

char sentence[size],ch;

int i,j,maximum, ind=0, counts[numberOfLetters];

cout<<"Enter the phrase: ";
cin.getline(sentence, 200);

for (int i = 0; i < numberOfLetters; i++){
counts[i] = 0;
}

for (int i = 0; i < numberOfLetters; i++){
counts[sentence[i] - 'a']++;
}

cout<<endl;

maximum=0;

for(i=0;i<numberOfLetters;i++){
if(maximum<=counts[i]){
maximum=counts[i];
ch=char(i + 'a');
}
}

for(i=0;i<size;i++){
if(sentence[i]==ch){
ind=i;
}
}
cout<<"Most frequent letter: "<<ch<<", "<<maximum <<" times, last seen at index "<<ind;
}