fork download
  1. //Devin Scheu CS1A Chapter 4, P. 220, #3
  2. //
  3. /**************************************************************
  4. *
  5. * DETERMINE IF DATE IS MAGIC
  6. * ____________________________________________________________
  7. * This program asks for a month (in numeric form),
  8. * a day, and a two-digit year, then checks if the month times
  9. * the day equals the year.
  10. *
  11. * Computation is based on the condition:
  12. * isMagic = (month * day == year)
  13. * ____________________________________________________________
  14. * INPUT
  15. * month : The month in numeric form (as an integer)
  16. * day : The day of the month (as an integer)
  17. * year : The two-digit year (as an integer)
  18. *
  19. * OUTPUT
  20. * message : Indicates whether the date is magic or not
  21. *
  22. **************************************************************/
  23.  
  24. #include <iostream>
  25. #include <iomanip>
  26. #include <string>
  27.  
  28. using namespace std;
  29.  
  30. int main () {
  31.  
  32. //Variable Declarations
  33. int month; //INPUT - The month in numeric form (as an integer)
  34. int day; //INPUT - The day of the month (as an integer)
  35. int year; //INPUT - The two-digit year (as an integer)
  36. string message; //OUTPUT - Indicates whether the date is magic or not
  37.  
  38. //Prompt for Input
  39. cout << "Enter the month (1-12): ";
  40. cin >> month;
  41. cout << "\nEnter the day: ";
  42. cin >> day;
  43. cout << "\nEnter the two-digit year: ";
  44. cin >> year;
  45.  
  46. //Determine if Date is Magic
  47. if (month * day == year) {
  48. message = "The date is magic!";
  49. } else {
  50. message = "The date is not magic.";
  51. }
  52.  
  53. //Output Result
  54. cout << "\n";
  55. cout << left << setw(25) << "Month:" << right << setw(15) << month << endl;
  56. cout << left << setw(25) << "Day:" << right << setw(15) << day << endl;
  57. cout << left << setw(25) << "Year:" << right << setw(15) << year << endl;
  58. cout << left << setw(25) << "Result:" << right << setw(15) << message << endl;
  59.  
  60. } //end of main()
Success #stdin #stdout 0.01s 5320KB
stdin
1
2
2
stdout
Enter the month (1-12): 
Enter the day: 
Enter the two-digit year: 
Month:                                 1
Day:                                   2
Year:                                  2
Result:                  The date is magic!