Re: really need your help
Re: really need your help
[ removed duplicate thread ]
Please do not create multiple threads about the same issue.
And please try to give a meaningful title to your threads.
Re: really need your help
Code:
#include <iostream>
int main(int argc,char * argv[])
{
char chInput = 0;
cin << chInput;
if ( (chInput >= 'A' && chInput <= 'Z') || (chInput >= 'a' && chInput <= 'z') )
{
std::cout << "Your input is a Character.";
}
else if ( chInput >= '0' && chInput <= '9' )
{
std::cout << "Your input is an Integer.";
}
else
{
std::cout << "Invalid input.";
}
return 0;
}
To explain that code example to a beginner at C++, a character holds ASCII text values. In the ASCII code table the characters 'A' and 'Z' are arranged in order from A to Z. Same goes for '0' to '9'. So you just compare the character input against the literal character values.
If input is greater than or equal to 'A' and less than or equal to 'Z', or if input is greater than or equal to 'a' and less than equal to 'z', then it's a character.
If the input is greater than or equal to '0' and less than or equal to '9', then it is an integer.
Re: really need your help
Quote:
Originally Posted by
CppCoder2010
To explain that code example to a beginner at C++,
http://www.codeguru.com/forum/showpo...18&postcount=2
Stick to explaining without the code. We don't do homework for others here.
Regards,
Paul McKenzie