-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquestion4.cpp
More file actions
35 lines (29 loc) · 985 Bytes
/
question4.cpp
File metadata and controls
35 lines (29 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* Write a program using functions that determines whether a character input by a
* user is uppercase or lower case.
*/
#include <iostream>
#include <cctype>
// Function to determine whether the character entered by the user is in upper case or lower case
void determineCase(char character) {
if (std::isalpha(character)) {
if (std::isupper(character)) {
std::cout << "The character '" << character << "' is uppercase.\n";
} else {
std::cout << "The character '" << character << "' is lowercase.\n";
}
} else {
// Gracefully handle a case where the user enters a number
std::cout << "Invalid input! Please enter a single letter.";
}
}
int main() {
// Declaration of variables
char character;
// Prompt the user to enter a character
std::cout << "Enter a single character (letter): ";
std::cin >> character;
// Call our function
determineCase(character);
return 0;
}