Program is supposed to find the Uppercase letters and give their total in a sentence... NEED HELP AS SOON AS POSSIBLE

// Program CountUC counts the number of uppercase letters
// on a line.
#include <iostream>
using namespace std;
bool IsUppercase(char);
int main ()
{
char letter;
int letterCt = 0;

cout << "Please enter a sentence: " << endl;
cin.get(letter);
while (letter != '\n')
{
if (IsUppercase(letter));
letterCt++;
cin.get(letter);
cout << letterCt << endl;
}
return 0;
}
bool IsUppercase(char letter)
{
return (letter >= 'A' && letter <= 'Z');
}
What is the problem . what is the error you are getting ??
No error but it is giving me all the characters in integers. I just want the Uppercase
Do you want the char or sentence to check for the upper case .
Not sure what you mean. They enter a sentence. I search and find Uppercase. I then output the number of Uppercase letters.
Some modification in the code .
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;
bool IsUppercase(char);
int main ()
{
	char letter[200];
	int letterCt = 0, count = 0 ;

	cout << "Please enter a sentence: " << endl; 
	cin.get(letter);
	while (letter[count] != '\0')
	{
		if (IsUppercase(letter));
			letterCt++;
		
		count++;
	}
	cout<<"\n The count of the upper case letter = 1" <<count++;
	return 0;
}
bool IsUppercase(char letter)
{
	return (letter >= 'A' && letter <= 'Z');
}
That seems to have sound logic but I get an error when running this: "empty controlled statement found"
If anyone else has suggestions it would be much appreciated
The semi-colon ; after your if() statament ends it, so the following
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
bool IsUppercase(char);
int main()
{
	char letter;
	int letterCt = 0;

	cout << "Please enter a sentence: " << endl;
	cin.get(letter);
	while(letter != '\n')
	{
		if(IsUppercase(letter)); // The ; is ending the if() statement
		letterCt++; // this is not in the if statement
		cin.get(letter);
		cout << letterCt << endl;
	}
	return 0;
}
bool IsUppercase(char letter)
{
	return (letter >= 'A' && letter <= 'Z');
}

Try this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;
bool IsUppercase(char);
int main()
{
	char letter;
	int letterCt = 0;

	cout << "Please enter a sentence: " << endl;
	cin.get(letter);
	while(letter != '\n')
	{
		if(IsUppercase(letter)) // REMOVED the ;
			letterCt++; // NOW this is in the if statement
		cin.get(letter);
		cout << letterCt << endl;
	}
	return 0;
}
bool IsUppercase(char letter)
{
	return (letter >= 'A' && letter <= 'Z');
}
Last edited on
Thanks a BILLION!!! so all I needed to do from my original was remove the semi-colon?
Topic archived. No new replies allowed.