#include <iostream>
#include <cstring>
usingnamespace std;
int find_letter(char str[], char a);
int main()
{
if (system("CLS")) system("clear"); //clears garbage from screen
int result = 0; //counter
int count;
char string[100];
char letter;
//prompts user for string
cout <<"Enter in a string (maximum of 40):" << endl;
cin.getline(string, 80);
//searches for the letter
cout << "Enter in a character: ";
cin >> letter;
cout << "Searching for the " << letter << " that appear in the string: " << string <<endl;
count = find_letter(string, letter);
cout << "The number of times the letter " << letter << " Appears in the string is: " << result << endl;
return 0;
}
int find_letter(char str[], char a)
{
int result;
result = 0;
//loops program to check multiple stored characters
for(int i = 0; i < strlen(str); i++)
{
if(str[i]==a)
result++;
}
return result;
}
you are storing your results in the count variable
but you are using result.
1 2 3 4
cout << "Searching for the " << letter << " that appear in the string: " << string <<endl;
count = find_letter(string, letter);
// result should be count
cout << "The number of times the letter " << letter << " Appears in the string is: " << result << endl;