// classifyChar2.cpp
// Classifies a single character entered by the user
// via cin's get function.
#include <iostream>
using namespace std;
int main()
{
// Announce purpose of program:
cout << "This program classifies an entered character." << endl;
// Input a character:
cout << "Enter a character:>";
char entry; // to be input from user
cin.get(entry);
// Output the character and its ASCII value:
cout << "You typed: " << entry << endl;
cout << "The numeric value of its binary code is: "
<< (int) entry << endl;
cout << "It is ";
// Classify the character:
if ( entry < 0 )
cout << "a non-ASCII character." << endl;
else if ( entry == ' ' )
cout << "an ASCII space." << endl;
else if ( entry >= '0' && entry <= '9' )
cout << "an ASCII digit." << endl;
else if ( (entry >= 'A' && entry <= 'Z')
|| (entry >= 'a' && entry <= 'z') )
cout << "an ASCII letter." << endl;
else if ( entry < 32 || entry == 127 )
cout << "an ASCII control character." << endl;
else
cout << "an ASCII punctuation mark." << endl;
return 0;
} // function main