FIND Nationality and his/her eyecolor in 2d array in c#.
Take N number of user data input and make sure N is greater then 10, which contain name of the user, his/her nationality and his/her eye color. You have to show the max color of eye in each country.
CODE:
DateTime dt = DateTime.Now;
Console.WriteLine("{0}", dt);
Console.WriteLine("Number Of Records ");
int n = Convert.ToInt32(Console.ReadLine());
if (n <= 5)
{
Console.WriteLine("Please enter more than 10 records.");
return;
}
String[,] data = new string[n, 3];
for (int i = 0; i < data.GetLength(0); i++)
{
Console.WriteLine("Enter Data for Person {0}", i + 1);
for (int j = 0; j < 1; j++)
{
Console.WriteLine("Name");
data[i, 0] = Console.ReadLine().ToLower();
Console.WriteLine("Nationality");
data[i, 1] = Console.ReadLine().ToLower();
Console.WriteLine("Eye Color");
data[i, 2] = Console.ReadLine().ToLower();
}
}
int pblack = 0, pblue = 0, pgray = 0;
int iblack = 0, iblue = 0, igray = 0;
for (int i = 0; i < n; i++)
{
string nationality = data[i, 1];
string eyeColor = data[i, 2];
if (nationality == "Pak".ToLower())
{
if (eyeColor == "black")
{
pblack++;
}
else if (eyeColor == "blue")
{
pblue++;
}
else if (eyeColor == "gray")
{
pgray++;
}
}
else if (nationality == "India".ToLower())
{
if (eyeColor == "black")
{
iblack++;
}
else if (eyeColor == "blue")
{
iblue++;
}
else if (eyeColor == "gray")
{
igray++;
}
}
}
Console.WriteLine("Most Common Eye Color in Pakistan:");
if (pblack >= pblue && pblack >= pgray)
{
Console.WriteLine("Black: {0}", pblack);
}
else if (pblue >= pblack && pblue >= pgray)
{
Console.WriteLine("Blue: {0}", pblue);
}
else
{
Console.WriteLine("Gray: {0}", pgray);
}
Console.WriteLine("Most Common Eye Color in India :");
if (iblack >= iblue && iblack >= igray)
{
Console.WriteLine("Black: {0}", iblack);
}
else if (iblue >= iblack && iblue >= igray)
{
Console.WriteLine("Blue: {0}", iblue);
}
else
{
Console.WriteLine("Gray: {0}", igray);
}
Comments
Post a Comment