Alright, so i am in an intermediate programming class and we are using C++. But for the intro class, we learned python. That being said, i do not know much C++ at all. I have done a lot of searching and tried my best to set up this program but i just cannot get it to work correctly. It seems as though i have gotten down to just "identifier "" is undefined" errors and i dont know how to fix them. The program is supposed to take an entered email and check that it is formatted correctly.
My teacher suggested doing it this way: "To validate, check into the string variable defined in c++. Look at the methods that allow you to search a string looking for characters. Also look at the string methods that create string. You should be able to search a string for the @ and create substring of the parts. Then validate the parts."
Please help!
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
class emailverify
{
public: // global variables/functions
std::string test;
std::string email;
std::string at = "@";
std::string period = ".";
};
int main()
{
std::string test = "Y";
while (test == "Y" || test == "y") // while loop to keep asking for more emails if the user wishes to test another
{
cout << "Please enter a valid Email address.\n"; // asks for email
cin >> email;
if (email.find(at != std::string::npos))
{
if (email.find_last_of(period != std::string::npos))
{
cout << "This email is valid. Would you like to try another? (Y/N)\n"; // email passed both tests, so is valid, seeing if while loops continues or not
cin >> test;
}
else
{
cout << "This email is invalid, would you like to try another? (Y/N)\n"; // failed second test, so is not valid, seeing if while loop continues or not
cin >> test;
}
}
else
{
cout << "This email is invalid, would you like to try another? (Y/N)\n"; // failed first test, so is not valid, seeing if while loop continues or not
cin >> test;
}
} // while loop ends
return 0;
}