Advertisement
Sinux1

Lab11.cpp

Apr 26th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cctype>
  4. using namespace std;
  5.  
  6. void validate(string email)
  7. {
  8.     int dot_locate = 0;
  9.     int at_locate = 0;
  10.     if(email.find_first_of('@') == -1)
  11.     {
  12.         cout << "Missing @ symbol\n";
  13.         return;
  14.     }
  15.     for ( int sub = 0; sub < email.length(); sub++)
  16.     {
  17.         if (email[sub] == '.')
  18.         {
  19.             dot_locate = sub;
  20.         }
  21.         else if (email[sub] == '@')
  22.         {
  23.             at_locate = sub;
  24.         }
  25.     }
  26.     if (at_locate > dot_locate)
  27.     {
  28.         cout << "Missing . symbol after @\n";
  29.         return;
  30.     }
  31.     cout << "Email accepted.\n";
  32.     return;
  33.  
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39.     string input;
  40.     cout << "Enter your email address\n";
  41.     cin >> input;
  42.     validate(input);
  43.  
  44.  
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement