Pages

Sunday, November 1, 2015

C++ Program to Check If a Character is Small, Capital, Number or Special Character

The C++ Program checks if the value entered by a user is a capital, small, number or a special character. The output also returns the Ascii equivalent of the character. IF statement is used for flow of control in the program.

Also Read: C++ Program to Check If a Number Is A Perfect Number or NOt

C++ Program to Find All The Roots Of A Quadratic Equation
C++ Program to Compute The Least Common Multiple of Integers


#include <iostream.h>
int main()
{
char alphabet;

cout<<"enter an character: ";
cin>>alphabet;
int Ascii=alphabet;
if (Ascii>=97 && Ascii<=122)
{
cout<<"the Ascii equivalent of "<<alphabet<<" is: "<<Ascii<<endl;
cout<<"alpabet is a small letter";
}
else if (Ascii>=65 && Ascii<=90)
{
cout<<"the Ascii equivalent of "<<alphabet<<" is:" <<Ascii<<endl;
cout<<"The alphabet is a capital letter";

else if (Ascii>=47 && Ascii<=57)
{
cout<<"the Ascii equivalent of "<<alphabet<<"is: "<<Ascii<<endl;
cout<<"You entered a number";
}
else if (Ascii>=0 && Ascii>=47 || Ascii>=54 && Ascii<=64 || Ascii>=91 && Ascii<=96 || Ascii >=123 && Ascii<=127)
{
cout<<"the Ascii equivalent of "<<alphabet<<"is:"<<Ascii<<endl;
cout<<"you entered a special character";
}
return 0;
}