Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cctype>
- using namespace std;
- bool validate_input(string name)
- {
- bool flag = true;
- for(int sub = 0; sub < name.length(); sub++)
- {
- if(!isalpha(name[sub]))
- {
- flag = false;
- break;
- }
- }
- return flag;
- }
- bool is_odd(string name)
- {
- bool flag = false;
- if(name[0] % 2 == 1)
- flag = true;
- return flag;
- }
- int main()
- {
- string name;
- cout << "Enter your first name\n";
- cin >> name;
- if(validate_input(name))
- {
- cout << "Your nickname is:\n";
- if(is_odd(name))
- {
- cout << "Big ";
- for(int sub = 0; sub < 3; sub++)
- {
- cout << name[sub];
- }
- cout << endl;
- }
- else
- {
- cout << "Lil " ;
- for(int sub = 0; sub < 4; sub++)
- {
- cout << name[sub];
- }
- cout << endl;
- }
- }
- else
- {
- cout << "Only letters are allowed.\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement