Monthly Calendar
Summary
Arrays are powerful tools for efficiently performing the same operations on multiple data points. In this example, the operation will be simple, printing the data to the console, but the principle of working through an array doing the same thing with each element is fundamental.
Task
- Create a new console application
- Within main, declare a string array of 12 elements and initialise it with the names of the months of the year - You can use the {} notation.
- Now write code to loop through the array printing out the number of the month and the name of the month.
- Run the program and check that the results are correct.
Questions
- Humans think of January as the first month. What number does the computer think is January?
- Which is the best loop syntax to use here, for, while or do...while?
- Can you modify your code to print the days of the week instead? Is there anything you could have done differently to reduce the number of changes required to do so?