Write a program to declare 2 arrays to store the 5 users’ names and their respective passwords. The program should accept a user name and a password and search for the username. If the user name exists and the password matches for that particular user, then display the message, "Welcome ". If the username is not found or if the username is found but the password does not match, then display the message "Login failed". Sample usernames : robin, sanya, sunny, Rohit, vimal
Sample passwords : as12#dfg, AA123$sd, bv45ttt, cvn1990, kpk#12$gh
BLUE J JAVA
Answers
Answer:
static void Main(string[] args)
{
Console.WriteLine("This program allows you to write names to a list,");
int i = 0;
//Due to the fact than i cannont resize an array after initialization, i used a list and converted it to an array at a later point
List<string> names = new List<string>();
string name = " ";
Console.WriteLine("Enter names then press enter to add them to the list of names! if you wish to exit simple type exit.");
//This loop adds names to the list
while (name.ToLower() != "exit")
{
Console.WriteLine("Enter Name: ");
name = Console.ReadLine();
names.Add(name);
i++;
}
//This line converts the list to an array
string[] nameArray = names.ToArray();
for(int z = 0;z <nameArray.Length + 1;z++)
{
for (int y = 0; y < z ; y++)
{
if (nameArray[y] == nameArray[z])
{
Console.WriteLine("The name: " + nameArray[y] + " is a duplicate.");
}
else
{
Console.Write(" ");
}
}
}
Console.ReadLine();
}