Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cctype>
- using namespace std;
- void validate(string email)
- {
- int dot_locate = 0;
- int at_locate = 0;
- if(email.find_first_of('@') == -1)
- {
- cout << "Missing @ symbol\n";
- return;
- }
- for ( int sub = 0; sub < email.length(); sub++)
- {
- if (email[sub] == '.')
- {
- dot_locate = sub;
- }
- else if (email[sub] == '@')
- {
- at_locate = sub;
- }
- }
- if (at_locate > dot_locate)
- {
- cout << "Missing . symbol after @\n";
- return;
- }
- cout << "Email accepted.\n";
- return;
- }
- int main()
- {
- string input;
- cout << "Enter your email address\n";
- cin >> input;
- validate(input);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement