Hoping someone can help. I am teaching myself C# and one of the challenges in this chapter has tasked me with storing the number of days in each month in an array which I called daysInMonth. When the program starts, I am to ask for a user to input a number between 1 and 12 and then spit out the number of days in the month that corresponds with that number.
I have searched for this but am coming up with nothing. Most examples are related to matching/finding an int or string with something in the array which isn't what I want. I want something so that if the user enters the number 5, the program will print out whatever is in the 5th whatever in the array. I know this is pretty easy but I think that my searching is coming up with nothing because I don't know the correct term to search for. Any help would be appreciated.
UPDATE:
Thanks to MAV I got it working. Posting full code of the program.
int[] daysInMonth = new int[12] { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
string[] monthNames = new string[12] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
int myChoice;
Console.Write("Please enter a number: ");
myChoice = Int32.Parse(Console.ReadLine());
if (myChoice < 1)
{
Console.WriteLine("Sorry, the number {0} is too low. Please select a number between 1 and 12.", myChoice);
Console.Write("Please enter a number: ");
myChoice = Int32.Parse(Console.ReadLine());
}
else if (myChoice > 12)
{
Console.WriteLine("Sorry, the number {0} is too high. Please select a number between 1 and 12.", myChoice);
Console.Write("Please enter a number: ");
myChoice = Int32.Parse(Console.ReadLine());
}
int i = daysInMonth[myChoice - 1];
string m = monthNames[myChoice - 1];
Console.WriteLine("Thank you. You entered the number {0}.", myChoice);
Console.WriteLine("That number corresponds with the month of {0}.", m);
Console.WriteLine("There are {0} days in this month.", i);
Console.ReadLine();