Tutorial 13 - Validation


Home > Tutorials > Tutorial13

Question 1

For the following problem, work through steps 1 (Understanding) through 5 (Desk Checking) of the Steps in Program Development discussed in lectures.

Write a program to display the number of days in a month. The user is to input the month number. Validate the month number using an appropriate loop before determining the number of days in the month. Assume there are 28 days in February.

Example Runs

Run
Month Number (1 to 12, 0 to exit) ? 5
31 days

Month Number (1 to 12, 0 to exit) ? 2
28 days

Month Number (1 to 12, 0 to exit) ? 11
30 days

Month Number (1 to 12, 0 to exit) ? 13
Error: month number must be between 1 and 12, or 0 to Exit

Month Number (1 to 12, 0 to exit) ? 0

Question 2

What would the condition be for validating the month if -1 was used to exit the loop instead of 0? Desk check your condition with appropriate values.

Question 3

The above problem is a simplification of the real problem. What other information needs to be input by the user to be able to determine the correct number of days in a month? Under what circumstances is it needed?

Question 4

Catch up on any problems from previous tutorials that you haven't completed. Take this opportunity to discuss any queries or problems from previous tutorials with your tutor.


Previous Tutorial | Tutorial Index | Next Tutorial | Lecture
Last modified 03-Jan-2005 by Tim Whitfort.
Copyright © 2003-2005
Tim Whitfort