Sinux1

PS8Q6.cpp

May 3rd, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. using namespace std;
  4.  
  5. bool validate(string name)
  6. {
  7.     bool flag = true;
  8.     for(int sub = 0; sub < name.length(); sub++)
  9.     {
  10.         if(!isalpha(name[sub]))
  11.         {
  12.             cout << "Your name cannot contain: " << name[sub] << endl;
  13.             flag = false;
  14.         }
  15.     }
  16.     return flag;
  17. }
  18.  
  19. int main()
  20. {
  21.     string input;
  22.     cout << "What's your first name?\n";
  23.     cin >> input;
  24.  
  25.     if (validate(input))
  26.     {
  27.         cout << "Valid name.\n";
  28.     }
  29.     else
  30.         cout << "Invalid name.\n";
  31.  
  32.  
  33. }
Add Comment
Please, Sign In to add comment