aboutsummaryrefslogtreecommitdiffstats
path: root/ee1301/wk3/hw3_directory/strap012_HW3B.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ee1301/wk3/hw3_directory/strap012_HW3B.cpp')
-rw-r--r--ee1301/wk3/hw3_directory/strap012_HW3B.cpp52
1 files changed, 38 insertions, 14 deletions
diff --git a/ee1301/wk3/hw3_directory/strap012_HW3B.cpp b/ee1301/wk3/hw3_directory/strap012_HW3B.cpp
index 8a23e24..ffb669e 100644
--- a/ee1301/wk3/hw3_directory/strap012_HW3B.cpp
+++ b/ee1301/wk3/hw3_directory/strap012_HW3B.cpp
@@ -14,27 +14,51 @@ Character Detection
#include <iomanip>
using namespace std;
-int main () {
- char character;
- bool isNotAlphaNumeric=false;
- while (!isNotAlphaNumeric) {
- cout << "Enter a single digit or an alphabetic character: ";
- cin >> character;
- cout << "You entered " << character;
- if (character >= '0' && character <= '9')
+// Function: charTest
+// ---------------------------
+// Tests to see what kind of character was inputted
+// character: Self-explanatory
+// returns: 1 if number, 2 if lower case, 3 if upper case, 0 if not any of the previous
+
+int charTest (char character) {
+ if (character >= '0' && character <= '9')
{
- cout << ", which is a number." << endl;
+ return 1;
} else {
if (character>='a' && character<='z') {
- cout << ", which is a lower case letter." << endl;
+ return 2;
} else {
if (character>= 'A' && character<='Z') {
- cout << ", which is an upper case letter." << endl;
+ return 3;
} else {
- isNotAlphaNumeric=true;
- cout << ", which is not a letter or a number." << endl;
+ return 0;
}
}
- }
+ }
+}
+
+int main () {
+ int test;
+ char character;
+ bool isNotAlphaNumeric=false;
+ while (!isNotAlphaNumeric) {
+ cout << "Enter a single digit or an alphabetic character: ";
+ cin >> character;
+ cout << "You entered " << character << ", ";
+ test = charTest(character);
+ if (test==0) {
+ isNotAlphaNumeric=true;
+ cout << "which is not a letter or a number.";
+ }
+ if (test==1) {
+ cout << "which is a number.";
+ }
+ if (test==2) {
+ cout << "which is a lower case letter.";
+ }
+ if (test==3) {
+ cout << "which is an upper case letter.";
+ }
+ cout << endl;
}
}