Answer to Question #330463 in C++ for Viloshini

Question #330463

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.



1
Expert's answer
2022-04-19T03:08:22-0400
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS