Write a program that prompts the user to enter a string and then prompts the
user to enter a character.The program should display the number of times the
character occurs in the string.
int main() { string str; char ch; int amount = 0; cout<<"Enter the string : "; getline(cin, str); cout<<"Enter the character to find : "; cin>>ch; for (int i = 0; i < str.size(); i++) if(str[i] == ch) amount++; cout<<"This character occurs in this string "<< amount <<" time(s)"<<endl;
Comments
Leave a comment