# 4 October

``// Assignment 4 solution.// Stylistic point (Dijkstra): function or program should have a// single entry point (main) and a single exit point (return 0). By// returning from the middle of the program, after an error message,// we're having multiple exits.#include <stdio.h>int main(){    int month, day;    printf("Enter month (1-12): ");    scanf("%d", &month);    if(month < 1 || month > 12)    {        printf("Invalid month.\n");        return 0;    }    printf("Enter day of month: ");    scanf("%d", &day);    int max_days;    switch(month)    {    case 2:        max_days = 28;        break;    case 4: case 6: case 9: case 11:        max_days = 30;        break;    default:        max_days = 31;    }    if(day < 1 || day > max_days)    {        printf("Invalid day.\n");        return 0;    }    switch(month)    {    case 1: printf("January"); break;    case 2: printf("February"); break;    case 3: printf("March"); break;    case 4: printf("April"); break;    case 5: printf("May"); break;    case 6: printf("June"); break;    case 7: printf("July"); break;    case 8: printf("August"); break;    case 9: printf("September"); break;    case 10: printf("October"); break;    case 11: printf("November"); break;    case 12: printf("December"); break;    }    printf(" %d", day);    switch(day)    {    case 1: case 21: case 31:        printf("st");        break;    case 2: case 22:        printf("nd");        break;    case 3: case 23:        printf("rd");        break;    default:        printf("th");    }    printf("\n");    return 0;}``

©2011 Christopher League · some rights reserved · CC by-sa