Program to classify character input.
Write a program that asks the user to enter a character. Implement the following algorithm. Don't use loops. You can use labels.
- User enters a character.
- If he enters a lowercase English character display "lowercase".
- If he enters an uppercase English character display "uppercase".
- If the character is a numeric digit display "It's a number".
- If he enters something else, display "Something else".
- If the user didn't enter $, repeat the above steps. Don't use loops.
- If the user entered $, your program should exit.
int main() { char c; // label this statement so that we can // come back to it if required lblX: cout << "Enter a char:"; cin >> c; if(c >= 'a' && c <= 'z') { cout << "Lowercase" << endl; } else if (c >= 'A' && c <= 'Z') { cout << "Uppercase" << endl; } else if(c >= '0' && c <= '9') { cout << "It's a digit"; } else { cout << "Something else"; } cout << endl; if(c != '$') { goto lblX; } cout << "Quitting..." << endl; return 0; }
My C/C++ Videos on Youtube
Here is the complete playlist for video lectures and tutorials for the absolute beginners. The language has been kept simple so that anybody can easily understand them. I have avoided complex jargon in these videos.
This Blog Post/Article "C Program to classify character input" by Parveen (Hoven) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Updated on 2020-02-07. Published on: 2016-03-18