77 961
Assignments Done
Successfully Done
In August 2019

Answer to Question #40124 in C++ for Mary

Question #40124
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.
Expert's answer
#include <iostream>
#include <conio.h>
#include <string>

using namespace std;

int main()
string str;
char ch;
int amount = 0;
cout<<"Enter the string : ";
getline(cin, str);
cout<<"Enter the character to find : ";
for (int i = 0; i < str.size(); i++)
if(str[i] == ch) amount++;
cout<<"This character occurs in this string "<< amount <<" time(s)"<<endl;

return 0;


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be first!

Leave a comment

Ask Your question

Privacy policy Terms and Conditions