figured it out but have one question

This is a discussion on figured it out but have one question within the C++ Programming forums, part of the General Programming Boards category; I just did my 2nd one and I pretty much did it the same but I used the float A; ...

figured it out but have one question

I just did my 2nd one and I pretty much did it the same but I used the float A; then I used A as the cin>>. So of course it didnt work, I then put Char C as directed by soemone else and kept the same stuff and wow, it worked. So how come I had to use a Char C? I was reading but I'm still a little fuzzy on the details, it worked for digits, letters but what is the difference vs. int or float? Thanks

Bryan Oh ya, here is my new code

Code:

#include <iostream>
using namespace std;
int main()
{
char C;
cout << "Enter any character then press enter:" << endl;
cin >> C;
if (C>='A' && C<='Z')
cout << "The character you entered was a Upper-Case Letter" << endl;
else if (C>='a' && C<='z')
cout << "The character you entered was a Lower-Case Letter" << endl;
else if (C>='0' && C<='9')
cout << "The character you entered was a Digit" << endl;
else
cout << "The character you entered was none of the above" << endl;
return 0;
}

"char" holds any one single character. It can be a single digit, a letter, or another symbol entirely.

"float" can only hold numbers, it could never hold a letter or anything else besides a number. So if you type a letter when you are trying to read a float, the read will fail. A float can never, ever hold anything besides a number.

Same with an "int" -- it, too, can only hold numbers and nothing else.

Essentially, in your program, you were trying to determine if a CHARACTER was a letter, number, or other, so you wanted to read a char. If you had tried to read an int, and the user had entered "C", your variable would NOT hold 'C', it would hold an unknown integer (the read would fail and the number might be anything, but it will always be a number).

I understand that now, and I remember that back in the first 2 chapters..thanks..I do have one more question, sorry. Instead of putting c>= for my statements I could have put inputChar >=...I take it these two mean the same thing?