I have a problem with this code. It's our activity in school a while ago and I cant finish it. The problem is if I enter the correct username and password in any of the accounts at the first attempt, the "Invalid Input" is still showing up even though it says "Welcome (username)" then the "Enter Username>> "and I have to enter the username and password again until I finish 3 tries then the code ends(same with second attempt and in the third attempt the "Invalid Input" still shows up). What do I do? What will I add or remove in my code?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
String username;
String password;
String[,] accnts = { {"cads123","dadada"},{"carladrian","fafafa"},{"delossantos","gagaga"}};
int row;
for (int x = 3; x >= 1; x-- )
{
Console.WriteLine("You have "+ x + " attempt/s.");
Console.Write("Enter Username>> ");
username = Console.ReadLine();
Console.Write("Enter Password>> ");
password = Console.ReadLine();
for (row = 0; row < 3; row++)
{
if (username.Equals(accnts[row,0]) && password.Equals(accnts[row,1]))
{
Console.WriteLine("Welcome "+accnts[row,0]+"!");
break;
}
else
{
Console.WriteLine("Invalid Input.");
if (x != 1)
{
Console.WriteLine("Please Try Again.");
Console.Write("\n");
}
else if (x.Equals(1))
{
Console.Write("Goodbye!");
break;
}
}
}
}
Console.ReadKey();
}
}
}