Question #59371

Student e-mail IDs at Pace University consist of the first and last initials of the student, followed by five digits, followed by either the letter n or the letter p.
Write a program that asks the user to enter a Pace e-mail ID. The program should then validate the form of the ID as just described. If the ID is invalid, the pro- gram should tell the user which part (or parts) of the ID is invalid. If the ID is valid, the program should display an appropriate message.
1

Expert's answer

2016-04-20T11:25:05-0400

Question #59371, Programming & Computer Science / C# | completed

Program.cs

static void Main(string[] args)
{
    Console.Write("Enter your e-mail IDs at Pace University: ");
    string id = "";
    try
    {
        id = Console.ReadLine();
        char s = id[0];
        if (!Char.IsLetter(id[0]) || !Char.IsLetter(id[1]))
            throw new Exception("in the first and last initials");
        for (int i = 2; i < 7; i++)
        {
            if (!char.IsDigit(id[i]))
            {
                throw new Exception("in digits");
            }
        }
    }
    if (Char.ToLower(id[7]) != 'p' && Char.ToLower(id[7]) != 'n')
        throw new Exception("in the last letter");
    Console.Write("SUCCESS!");
}
catch (Exception e)
{
    Console.WriteLine("Error " + e.Message + "!");
}
Console.ReadKey();
}
}


http://www.AssignmentExpert.com/

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS