Friday, November 18, 2016

Programming Challenge 4.3 - Magic Date

/* Magic Date - This program asks the user to enter a month (in numeric form), a
   day, and a two-digit year. The program determines whether the month times the
   day is equal to the year. If so, it displays a message saying the date is magic.
   Otherwise it displays a message saying the date is not magic. */

#include "Utility.h"

int main()
{
    /* Hold variables for day, month, year and magic date */
    int day,
         month,
         year,
         magicDate;

    /* Ask the user for a day, a month and a two-digit year */
    cout << "Please enter a day: ";
    cin >> day;
    cout << "Now enter a month: ";
    cin >> month;
    cout << "And finally a two-digit year: ";
    cin >> year;

    /* Calculating the magic date */
    magicDate = month * day;

    /* Determine whether it is a magic date or not */
    if (year == magicDate)
    {
        cout << day << "/" << month << "/" << year << " This is a magic date!\n";
    }
    else
    {
        cout << "This date is not magic.\n";
    }

    pauseSystem();
    return 0;
}

1 comment:

  1. how about input validation on what range for month and day?
    in the context of a date like 31st April..its non existent..
    how do u handle such exception?

    ReplyDelete