Check character is uppercase, lowercase, digit or symbol in C++
if else if - Question 4
In this question, we will see how input a character and check if it is an uppercase alphabet or lowercase alphabet or digit or a special symbol in C++ programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.
Q4) Write a program in C++ to input a character and check if it is an uppercase alphabet or lowercase alphabet or digit or a special symbol.
Program
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
char c;
cout<<"Enter a character ";
cin>>c;
if(c>='A' && c<='Z')
{
cout<<"Uppercase alphabet";
}
else if(c>='a' && c<='z')
{
cout<<"Lowercase alphabet";
}
else if(c>='0' && c<='9')
{
cout<<"Digit";
}
else
{
cout<<"Special symbol";
}
return 0;
}
Output
Enter a character 8 Digit