Counting Uppercase in a string giving wrong output

So this is a exercise for basic intro into programming. It involves a while loop. User is to input a string of upper or lower, and output will count the Uppercase.

My code works in counting the upper case in input string, say "AbbaIsAnnoying," but the output is what's looking screwy. I know I'm missing something simple, but I think my lack of experience may be missing it.

Suggestions?

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
 // Program CountUC counts the number of uppercase letters
// on a line.

#include <iostream>

using namespace std;

int main ()
{ 
	char letter;
	int letterCt = 0;

	cout << "Enter a string of Letters (upper and lower): ";
	cin >> letter;
	cout << endl;

	while(letter != '\n')
	{
		if(letter >= 'A' && letter <= 'Z')
			letterCt++;
		cin.get(letter);
		
		cout << letterCt << endl;
	
	}

	return 0;
}


This is what the output looks like:

Enter a string of Letters (upper and lower): AbbaIsAnnoying

1
1
1
1
2
2
3
3
3
3
3
3
3
3
Press any key to continue . . .
Swap lines 23 and 25 - isn't that what you meant to do anyway?
Oh my gosh...it was that easy... *sigh*

Thanks L B.

Sometimes it takes a fresh pair of eyes, eh?
Topic archived. No new replies allowed.