fork download
  1. // Chapter 4 - Programming Challenge #3
  2. // Magic Dates
  3. // This program asks the user to enter a month, day,
  4. // and two-digit year. It determines whether the date
  5. // is a "magic date" by checking if the month times
  6. // the day is equal to the year.
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main()
  12. {
  13. // Variables to store the month, day, and two-digit year
  14. int month, day, year;
  15.  
  16. // Get the month from the user
  17. cout << "Enter a month: ";
  18. cin >> month;
  19.  
  20. // Get the day from the user
  21. cout << "Enter a day: ";
  22. cin >> day;
  23.  
  24. // Get the two-digit year from the user
  25. cout << "Enter a two-digit year: ";
  26. cin >> year;
  27.  
  28. // Check if the month multiplied by the day
  29. // is equal to the year
  30. if (month * day == year)
  31. {
  32. cout << "The date is magic!" << endl;
  33. }
  34. else
  35. {
  36. cout << "The date is not magic." << endl;
  37. }
  38.  
  39. return 0;
  40. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Enter a month: Enter a day: Enter a two-digit year: The date is not magic.