-2
#include <cstdlib>

using namespace std;

int main()
{
 //define a list of vars & input
  int month;
  int day;
  int year;




 //processing

 //output
 cout<<"Enter Month: "<< "Press Enter Key" <<endl;
 cin >> month;
 cout<<"Enter Day: "<< "Press Enter Key" <<endl;
 cin >> day;
 cout<<"Enter Year: "<< "Press Enter Key" <<endl;
 cin >> year;

 int date = int (month * day);

 if  (date == year)
         cout<<"date"<<"is not magic"<<endl;
 else
         cout<<"date"<<"is magic"<<endl;

 return 0;

}

I'm trying to 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, also to put the date in numeric form. Just started learning c/c++ recently and having trouble understanding it.

pmg
  • 106,608
  • 13
  • 126
  • 198
Omar
  • 13
  • 1

1 Answers1

1

You are checking the opposite condition:

if(date == year) {
    //it is magic, but
    cout << "date is not magic" << endl;
} else {
    //it isn't magic, but
    cout << "date is magic" << endl;
}

To display the date, just do something like

cout << day << "/" << month << "/" << year << endl;

To wrap it all up, when working on bigger projects, using namespace is bad and creates confusion, not to mention it in headers, which is basically a coding crime. Read more about it here

lenerdv
  • 177
  • 13