Advertisement
Sinux1

PracticeFinal2.cpp

May 17th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. bool validate_input(string name)
  7. {
  8.     bool flag = true;
  9.     for(int sub = 0; sub < name.length(); sub++)
  10.     {
  11.         if(!isalpha(name[sub]))
  12.         {
  13.             flag = false;
  14.             break;
  15.         }
  16.  
  17.     }
  18.     return flag;
  19.  
  20. }
  21.  
  22. bool is_odd(string name)
  23. {
  24.     bool flag = false;
  25.     if(name[0] % 2 == 1)
  26.         flag = true;
  27.  
  28.     return flag;
  29.  
  30. }
  31.  
  32. int main()
  33. {
  34.     string name;
  35.     cout << "Enter your first name\n";
  36.     cin >> name;
  37.  
  38.  
  39.  
  40.     if(validate_input(name))
  41.     {
  42.         cout << "Your nickname is:\n";
  43.         if(is_odd(name))
  44.         {
  45.             cout << "Big ";
  46.             for(int sub = 0; sub < 3; sub++)
  47.             {
  48.                 cout << name[sub];
  49.             }
  50.             cout << endl;
  51.         }
  52.         else
  53.             {
  54.             cout << "Lil " ;
  55.             for(int sub = 0; sub < 4; sub++)
  56.             {
  57.                 cout << name[sub];
  58.             }
  59.             cout << endl;
  60.         }
  61.  
  62.     }
  63.     else
  64.     {
  65.         cout << "Only letters are allowed.\n";
  66.     }
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement