Programming Challenge Chapter 4 – Q #3 Magic Dates – Tony Gaddis – Starting Out With C++

Programming Challenge Chapter 4 – Q #3 Magic Dates  – Tony Gaddis – Starting Out With C++




Problem: -

Magic Dates

The date June 10, 1960 is special because when we write it in the following format, the month times the day equals the year.
6/10/60
Write a program that asks the user to enter a month (in numeric form), a day, and a two-digit year. The program should then determine whether the month times the day is equal to the year. If so, it should display a message saying the date is magic. Otherwise it should display a message saying the date is not magic.

Solution: -

#include<iostream>
using namespace std;
int main()
{
//Declare Variables
int date, month, year, magic_date;

    //Take Input By User
cout << "Enter date: ";
cin >> date;
cout << "Enter month: ";
cin >> month;
cout << "Enter two digit year: ";
cin >> year;
//Calculate The Magic Date 
magic_date = date * month;

    //Use IF Condition for cheacking magic year
if (magic_date == year)
cout << "This is magic date";
else
cout << "This is not a magic date";

    //Return 0 To the main Function
return 0;

}

This is the solution of this question




OUTPUT OF THIS QUESTION



Explanation of this Solution

Solution Explain With Comments in Solution.


Also, I attach CPP file of this problem. You can download this file

Click Here to Download This File

Post a Comment

0 Comments