How to get the number of letters of inputted words?

How do you get the lowercase and uppercase letter count of a inputted word?

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  #include <iostream>
using namespace std;

int main()
{
	char word[100];
	int count[100];
	int count2[100];
	
	
	//Basic I/O
	cout<<"Enter the word: ";
	gets(word);


	//To initialize to 0
	for(int i=0; i <= 100; i++)
	{
		count[i] = 0;
		count2[i] = 0;
	}
	
	
	//For getting the count of uppercase letters
	for(int i=0; i <= 100; i++)
	{
		for(int j=0; j <= 100; j++)
		{
			if(word[i] == char(65+j))
			{
					count[j]+=1;
			}////////// END //////////
		}////////// END //////////
	}////////// END //////////
	
	
	//For getting the count of lowercase letters
	for(int i=0; i <= 100; i++)
	{
		for(int j=0; j <= 100; j++)
		{
			if(word[i] == char(97+j))
			{
				count2[j]+=1;
			}////////// END //////////
		}////////// END //////////
	}////////// END //////////
	
	
	//Output of individual uppercase. If letter is == 0, will not output letter.
	for(int i=0; i <= 100; i++)
	{
		if(count[i] != 0)
		{
			cout<<char(65+i)<<" = "<<count[i]<<"\t";
		}////////// END //////////
	}////////// END //////////
	cout<<endl<<endl;
	
	
	//Output for individual lowercase. If letter is ==0, will not output letter.
	for(int i=0; i <= 100; i++)
	{
		if(count2[i] != 0)
		{
			cout<<char(97+i)<<" = "<<count2[i]<<"\t";
		}////////// END //////////
	}////////// END //////////
	
	cin.get();
	return 0;
}


Sample output:

Enter Word: BeAsst
A = 1
B = 1
e = 1
s = 2
t = 1
http://www.cplusplus.com/reference/cctype/isupper/
or std::isupper from locale

Same with islower.
Still doesn't work...
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
	//To initialize to 0
	for(int i=0; i <= 100; i++)
	{
		count[i] = 0;
		count2[i] = 0;
	}
	
	
	for(int i=0; i <= 100; i++)
	{
		if(isupper(word[i]))
		count[i]+=1;
		
		if(islower(word[i]))
		count2[i]+=1;
	}
	
	
	//Output of individual uppercase. If letter is == 0, will not output letter.
	for(int i=0; i < 25; i++)
	{
		
		if(word[i] != 0)
			cout<<char(65+i)<<" = "<<count[i]<<"\t";
		////////// END //////////
	}////////// END //////////
	cout<<endl<<endl;
	
	
	//Output for individual lowercase. If letter is ==0, will not output letter.
	for(int i=0; i < 25; i++)
	{
		
		if(word[i] != 0
			cout<<char(97+i)<<" = "<<count2[i]<<"\t";
		////////// END //////////
	}////////// END //////////
	cin.get();
	return 0;
Topic archived. No new replies allowed.