diff options
author | RossTheRoss <msattr@gmail.com> | 2019-02-26 14:00:34 -0600 |
---|---|---|
committer | RossTheRoss <msattr@gmail.com> | 2019-02-26 14:00:34 -0600 |
commit | 0cf7e0d3e1a3506533fa27ef712ee612e3fa8657 (patch) | |
tree | 040c783ca429a61e4d25b911c7603a71d52eb1bc /ee1301/wk3/hw3_directory/strap012_HW3B.cpp | |
parent | MEANINGFUL C O M M E N T (diff) | |
download | homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.tar homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.tar.gz homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.tar.bz2 homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.tar.lz homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.tar.xz homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.tar.zst homework-0cf7e0d3e1a3506533fa27ef712ee612e3fa8657.zip |
MEANINGFUL CO M M EN TS
Also making 3B a function cause why not.
Diffstat (limited to 'ee1301/wk3/hw3_directory/strap012_HW3B.cpp')
-rw-r--r-- | ee1301/wk3/hw3_directory/strap012_HW3B.cpp | 52 |
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; } } |