Write a program to determine the entered character is an alphabet or number or special character using if – else-if – else.
Instruction: This program read a character value from the user and displays whether it is an alphabet or number or special character, with a suitable message.
#include <iostream>
#include <cctype>
using namespace std;
int main() {
  char ch;
  cout << "Enter a character: ";
  cin >> ch;
  if (isalpha(ch)) {
    cout << "It is an alphabet character" << endl;
  }
  else if (isdigit(ch)) {
    cout << "It is a digit" << endl;
  }
  else if (ispunct(ch)) {
    cout << "It is a punctuation" << endl;
  }
  else {
    cout << "It is something unknown" << endl;
  }
  return 0;
}
Comments
Leave a comment