Select Case statements - a calendar
Until now, we have used IF...Then statements to give a user a choice between 2 or 3 options - as in the driving license example.
What if there were 12 choices? We would have to have an if statements with 11 else conditions following it - this would be repetitive and very time-consuming to type in.
Instead, we use something called a
Select Case statement. Using this a user can choose between multiple 'Cases' (or options) with the minimum amount of coding.


To allow you to work with Select Case statements we will design a simple calculator which tells the user how many days there are in the month whose number they type in.

The algorithm will work as follows:

- the user will type in the
number of the month  (i.e. 1 = January or 11 = November)
- the program will tell the user how many days that month has.



Task 1

How many Cases will this program have?
Hint: How many months have 30 days, how many have 31?.....and so on


Task 2
Type in the code below and test its functionality for each month of the year from 1 to 12

Back to Main Page
The general format of the Select Case statement is as follows:

Select Case (expression)             
- what the select is based on, in our case Month
Case value 1
          code to execute for case 1
Case value 2
          code to execute for case 2

...and so on until last case

Select End
Task 3

Write a program which will tell students their tutor's name and their classroom number when they enter their group number.

There are 3 groups of students studying IT at Anytown College, the groups are numbered 1, 2 and 3.
Group 1's tutor is Mr Singh, they meet in Room S204
Group 2's tutor is Miss Howard, they meet in Room A409
Group 3's tutor is Mr Hussain, they meet in Room S322

The algorithm should work as follows:

- The user enters a group number 1, 2 or 3
- An appropriate message is displayed telling them:

a) Their tutor's name
b) Which room they should go to

As usual, save a copy of your program to floppy disk and print out a copy of your code.


End of tasks

Hosted by www.Geocities.ws

1