Search⌘ K

Solution Review: Check if the Given Character is an Alphabet

Explore how to apply conditional statements in C++ to check if a character is an alphabet, distinguishing between uppercase and lowercase letters. This lesson guides you through the logic and implementation, enhancing your understanding of character handling and conditional flow in C++ programming.

We'll cover the following...

Solution #

Run the code below and see the output!

C++
#include <iostream>
using namespace std;
int main() {
// Initialize variable character
char character = 'a';
// if block
if (character >= 'A' && character <= 'Z') {
cout << "upper-case alphabet";
}
// else if block
else if (character >= 'a' && character <= 'z') {
cout << "lower-case alphabet";
}
// else block
else {
cout << "not an alphabet";
}
return 0;
}

Explanation

Line No. 7: Sets the value of a character to a

Line No. 10 ...