Password Learn programming with C# Sharp exercises

Lesson:

Flow Control


Exercise:

Password 108


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");
    }
}