I am trying to write a function in which the user enters a sentence in a string. Then specifies a letter to count in the sentence. The function will serarch the array to see how many times the letter specified appears. This is what I have so far....any help?????
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int main()
{
string str;
int i,index = 0, count = 0;
int letter;
char ch = 0;
cout << "Enter a string: " << endl;
cin >> str;
cout << "Enter the character you wish to count: " << endl;
cin >> letter;
index = str.find(ch, letter);
for (i = ch; i < str.length(); i++)
{
ch = str.at(letter);
count = index+1;
index = str.find(ch,letter);
if (isalpha(letter))
count++;
}
cout << "The character " << letter << "was found " << count << " times" << endl;