Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ Ask the user for an email address. Determine if the input meets the stand

ID: 3779901 • Letter: I

Question

In c++ Ask the user for an email address. Determine if the input meets the standard for an email address. An email address must have an @ symbol. Further, an email address must have a period after the @ symbol.

This is my code:

#include <iostream>
#include <exception>

using namespace std;

int main ()
{

string s;

cout << "Enter your email address" << endl;
cin >> s;


size_t found1 = s.find("@");
size_t found2 = s.find(".");

if (found1 == string::npos)
cout << "Missing @ symbol" << endl;


else if (found2 == string::npos)
cout << "Missing . symbol after @" << endl;

else if (found2 == s.length()-1)
cout << "Missing @ after . symbol" << endl;


else
cout << "Email accepted." << endl;

return 0;
}

Outputs:

The output passed all email samples besides one and can not figure out what it is

Standard input test example com Required output Enter your email addressAn Missing symbol after An Standard Input test person examplecom Required output Enter your email address An Missing symbol after @Mn Standard input test. person xample.com Test Case 3 Passed! Your Program's output Enter your email address An Missing symbol after Mn Test Case 4 Failed Your Program's output Enter your email addressAn Email accepted. An Test Case 5 Passed!

Explanation / Answer

#include <iostream>
#include <exception>
using namespace std;
int main ()
{
string s;
cout << "Enter your email address" << endl;
cin >> s;
// get last occurance of @ and .
size_t found1 = s.find_last_of("@");
size_t found2 = s.find_last_of(".");
if (found1 == string::npos)
cout << "Missing @ symbol" << endl;
else if (found2 == string::npos)
cout << "Missing . symbol after @" << endl;
// check if position of . is greater than .
else if(int(found1)>int(found2))
cout << "Missing . symbol after @" << endl;
else
cout << "Email accepted." << endl;
return 0;
}
/*
sample output
Enter your email address
test.person.person@example.com
Email accepted.

Enter your email address
test.person@examplecom
Missing . symbol after @
*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote