Ejercicio
Contraseña
Objetivo
Escribe un programa en C# para pedir al usuario su login y su contraseña (ambos deben ser números enteros) y repítelo tantas veces como sea necesario, hasta que el login introducido sea "12" y la contraseña sea "1234".
Código de Ejemplo
using System; // Importing the System namespace to use Console functionalities
class Program
{
// Main method where the program execution begins
static void Main()
{
int login; // Declaring a variable to store the login
int password; // Declaring a variable to store the password
// Repeatedly prompt the user for login and password until they enter the correct ones
do
{
// Asking the user to enter their login (login should be an integer)
Console.Write("Enter your login: ");
login = int.Parse(Console.ReadLine()); // Reading the login entered by the user
// Asking the user to enter their password (password should be an integer)
Console.Write("Enter your password: ");
password = int.Parse(Console.ReadLine()); // Reading the password entered by the user
// If the login and password are not correct, the loop will repeat
if (login != 12 || password != 1234)
{
Console.WriteLine("Invalid login or password. Please try again."); // Informing the user about invalid login/password
}
} while (login != 12 || password != 1234); // The loop continues until both login and password are correct
// Displaying a success message once the correct login and password are entered
Console.WriteLine("Login successful!"); // Informing the user that the login was successful
}
}