Monthly Calendar

Line: Loopy Line, Array Line
Medium DifficultyIterationArrays Learning Outcome One Exercise
Type: Exercise
You should have completed:

Arithmetic Mean

Drinks Machine

This topic leads to:

Record Sales

Test Plan

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

  1. Create a new console application
  2. 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.
  3. Now write code to loop through the array printing out the number of the month and the name of the month.
  4. Run the program and check that the results are correct.

 

Questions

  1. Humans think of January as the first month. What number does the computer think is January?
  2. Which is the best loop syntax to use here, for, while or do...while?
  3. 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?