Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_leap_year(const int year);
  5. int days_in_month
  6.  
  7. int main()
  8. {
  9. int year = 0;
  10. int day = 0;
  11. bool day_valid = false;
  12.  
  13. while (!year)
  14. {
  15. cout << "Enter the year: ";
  16. cin >> year;
  17. if (year < 0 || year > 9999)
  18. {
  19. cout << "That's not a valid year!" << endl;
  20. year = 0;
  21. }
  22. }
  23.  
  24. while (!day_valid)
  25. {
  26. cout << "Enter the day of the week of January 1st, using 0 through 6." << endl;
  27. cout << "(0 = Sun, 1 = Mon, 2 = Tue, 3 = Wed, 4 = Thu, 5 Fri, 6 = Sat)" << endl;
  28. cin >> day;
  29. if (day < 0 || day > 6)
  30. cout << "That's not a valid day! Must be between 0 and 6!" << endl;
  31. else
  32. day_valid = true;
  33. }
  34. bool leap_year = is_leap_year(year);
  35. if (leap_year)
  36. {
  37. cout << year << " is a leap year." << endl;
  38. cout << "There are 29 days in February." << endl;
  39. }
  40. else
  41. {
  42. cout << year << " is not a leap year." << endl;
  43. cout << "There are 28 days in February." << endl;
  44. }
  45.  
  46. }
  47.  
  48. bool is_leap_year(const int year)
  49. {
  50. if (year%4==0)
  51. {
  52. if (year % 100 == 0 && year % 400 != 0)
  53. return false;
  54. return true;
  55. }
  56. return false;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement