+ 1

What is wrong in this code is C++? how to count letters in a word.

Hello I am doing this class in udemy and I did this code from the video exactly I dont know what is wrong. #include <iostream> #include <string> using namespace std; int main() { string word = ""; do { cout << "Enter a word that has at least 5 characters:"<< endl; cin>> word; }while(word.size() < 5); char searchCh = '0'; cout <<"Enter the character and the program will tell you how many times it appears in the word"<< word<<"."<<endl; cin>> searchCh; int counter= 0; for(int i = 0; i< (int)word.size(); i++) { char ch =word.at(i); //if the character maches the chrachter we are lookingfor if(searchCh == ch) { counter++; //counter==counter+1 }//increment a couner } cout<<"The number of" <<searchCH<<"'S is the word"<< word<<"is"<<counter<<endl; }

7th Jan 2018, 1:20 AM
Bolivar Morales
Bolivar Morales - avatar
2 Respuestas
0
In line 36. (Last five line) It is not searchCH, it is searchCh. Solved :)
7th Jan 2018, 1:39 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 2
thank you it worked
7th Jan 2018, 1:42 AM
Bolivar Morales
Bolivar Morales - avatar