String keeps returning 0 for letters found

Hey there just learning some string and it keeps returning 0 for the letters found, any idea what I've messed up this time?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  #include <iostream>
#include <cstring>

using namespace 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;
wow, duh. Thanks. Sometimes you just need another persons eyes to tell you how slow you are haha.

Thanks!
Topic archived. No new replies allowed.