#include<iostream>using namespace std;
main(){ char ch; cin >> ch; // Read a character from user input
if (ch >= 'a' && ch <= 'z') cout << "Lowercase" << endl; // Check if the character is lowercase if (ch >= 'A' && ch <= 'Z') cout << "Uppercase" << endl; // Check if the character is uppercase if (ch >= '0' && ch <= '9') cout << "Numeric" << endl; // Check if the character is numeric}
#include<iostream>
using namespace std;
main()
{
char ch;
cin >> ch; // Read a character from user input
if (ch >= 'a' && ch <= 'z')
cout << "Lowercase" << endl; // Check if the character is lowercase
if (ch >= 'A' && ch <= 'Z')
cout << "Uppercase" << endl; // Check if the character is uppercase
if (ch >= '0' && ch <= '9')
cout << "Numeric" << endl; // Check if the character is numeric
}
What the Code Does
- Input: It reads a single character from the user.
- Condition Checks:
- Lowercase: If the character is between 'a' and 'z', it prints "Lowercase".
- Uppercase: If the character is between 'A' and 'Z', it prints "Uppercase".
- Numeric: If the character is between '0' and '9', it prints "Numeric".
This simple code helps categorize a character based on its type.
Key Points:
- Input Handling: The code reads a character from user input.
- Conditionals: It uses simple
if
statements to check if the character falls within the ranges for lowercase letters, uppercase letters, or numeric digits. - Output: Based on the checks, it outputs the character type.
This example demonstrates basic character classification in C++, essential for various programming tasks. Whether you're validating user input or processing text, knowing how to distinguish between character types is a fundamental skill in C++ programming.
For more detailed C++ programming tutorials and tips, stay tuned to our blog!
Keywords: C++ code character types, identify uppercase lowercase numeric C++, C++ character checks, determine character type in C++, C++ programming tutorial, character classification C++