so I basically just started learning computer programming (C#), and today I got to learn about Arrays. I kinda, sorta, understand what Arrays are , I know they are used for a way of keeping track of a list or collection of many related things all together. So I was thinking of making a program which asks the user for his name and after you put your name it would automatically give you the score that you got on "the test" so I wanna show you guys my code and I'll love some feedback on how can I make my code look better and shorter I guess.. anyways here's my code.
string studentNumberOne = "Miguel";
string studentNumberTwo = "Maddie";
string studentNumberThree = "John";
string studentName = ""; // Empty string variable for user input...
int[] grades = new int[3] { 90, 85, 70 }; // arrays, grades for each students...
Console.WriteLine("Please enter your name: "); // Asking the user to type his/her name
studentName = Convert.ToString(Console.ReadLine()); //
if (studentName == studentNumberOne)
{
Console.WriteLine(studentNumberOne + " your score was " + grades[0]);
}
else if (studentName == studentNumberTwo)
{
Console.WriteLine(studentNumberTwo + " your score was " + grades[1]);
}
else if (studentName == studentNumberThree)
{
Console.WriteLine(studentNumberThree +" your score was " + grades[2]);
}
}
}
I know there's a lot of if/else if's and that's why I'm asking for some feedback on how I can make this code better or shorter, I'm pretty sure there has to be a way with Arrays where you can store all three names that I have in my code and also give them their correspondent score, so yeah, I'll love the feedback, thank you! Also try to not go with crazy answer or too much details I guess, like I said I just started learning C# so try to make it as simple as possible so I can understand better (If you can or want).
PD : Sorry for my bad grammar, English is not my first language.