I'm "helping" a friend with something he's trying to do in C++, but I'm stuck because of the limitations: he isn't supposed to use any library functions. The objective is to take user input and determine if the input is an uppercase letter, a lowercase letter, a number, or some other character (like *, &, or #).
Here's what I have so far:
#include<string>
#include<vector>
#include<iostream>
using namespace std;
int main() {
string x = "";
vector<string> uppercaseAlphabet = {"A","B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
vector<string> lowercaseAlphabet = {"a","b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
cout<<"\nEnter a character.\n";
getline(cin, x);
if(std::find(uppercaseAlphabet.begin(), uppercaseAlphabet.end(), x) != uppercaseAlphabet.end()) {
cout<<"The input was an uppercase character.";
}
if(std::find(lowercaseAlphabet.begin(), lowercaseAlphabet.end(), x) != lowercaseAlphabet.end()) {
cout<<"The input was a lowercase character.";
}
return 0;
}
This isn't elegant, but it works so far. My problem is finding out when the user inputs a number. What's the best way to approach this?
I also don't know if I've violated the specifications by using things like find, begin, and end. Let me know if you think this wouldn't be allowed.
This is my first time writing any C++ so I'm sure my code doesn't follow any conventions. It also might be bad simply because of the using namespace std; line.