magic program

can someone help me please? 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.

this is what i have so far

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  int month, day, year;
    int magic;
    
    cout << "please enter a month, day and";
    cout << " year in numeric form\n";
    
cin >> month,day,year;
        
        magic = (month * day);
        
        if ( magic == year)
        {
            cout << "it is magic";
        }
        else 
        {
            cout << "not magic\n";
        }
        
        
You don't have to keep all the explanation stuff but I think it makes the program more understandable. Hope this helps!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;

int main(int argc, const char * argv[])
{
    int month, day, year;
    int magic;
    
    cout << "This program will determine ";
    cout << "if a certain date is *magic*.";
    cout << " First, pick any date.";
    cout << " Now, enter the numerical enterpretation";
    cout << " of the month that it's in. " << endl;
    cout << "(Ex: February 7th, 2014= 2):" << endl;
    cin >> month;
    cout << "Now enter the day " << endl;
    cout << "(Ex: March 31st, 2000= 31):" << endl;
    cin >> day;
    cout << "And finally, enter the";
    cout << " last two didgits of the year" << endl;
    cout << "(Ex: April 4th, 1996= 96):" << endl;
    cin >> year;
    
    magic = month * day;
    
    if (magic == year)
    {
        cout << "Your date is *magic*!\n";
    }
    else
    {
        cout << "Sorry, the date you entered is not *magic*.\n";
        cout << "Please feel free to try again!\n";
    }
    return 0;
}
Last edited on
Do this:
cin >> month >> day >> year;

But not this:
cin >> month,day,year;
Topic archived. No new replies allowed.