Password Learn programming C#

Lesson:

Flow Control


Exercise:

Password


Objetive:

Write a C# program to prompt the user to enter their login and password (both must be integer numbers) and repeat the prompt as many times as necessary until the entered login is "12" and the password is "1234".


Code:

using System;
public class Exercise30
{
    public static void Main()
    {
        int user, pass;

        do
        {
            Console.Write("Enter a user:  ");
            user = Convert.ToInt32(Console.ReadLine());

            Console.Write("Enter a password:  ");
            pass = Convert.ToInt32(Console.ReadLine());

            if ((user != 12) || (pass != 1234))
                Console.WriteLine("Login Error");

        }
        while ((user != 12) || (pass != 1234));

        Console.WriteLine("Login successful");
    }
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.