62 513
Assignments Done
98,8%
Successfully Done
In June 2018

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 : ";
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;

_getch();
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions