RSS Forums RSS
Please support our C++ advertiser: Programming Forums

Help with Creating a Yearly Calendar

Join Date: Jan 2007
Posts: 41
Reputation: raydogg57 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
raydogg57 raydogg57 is offline Offline
Light Poster

Re: Help with Creating a Yearly Calendar

  #3  
Jan 28th, 2007
Thanks! Yes I could tell it was an infinite loop and figured it had something to do with the for loop. So i took out the for loop and added all the '=='. Now I am trying to determine the number of days to print off per month. I believe I got every month all set except for February (because of leap years). What I was thinking of doing was making another function:

  1. bool IsLeapYear(int y)
  2. {
  3. if (the year is divisible by 400)
  4. it is a leap year;
  5. else if (the year is divisible by 4, but not 100)
  6. it is a leap year;
  7. else
  8. it is not a leap year;

But I am unclear as to how I actually program this function. I know that I can then do something like
  1. if IsLeapYear(y) == 1
  2. return 30;
  3. else
  4. return 29;

Here is my updated code thus far:

  1. #include <iostream>;
  2. #include <iomanip>;
  3.  
  4. using std::cin;
  5. using std::cout;
  6. using std::endl;
  7. using std::setw;
  8.  
  9. int First_Day_Of_Month(int y, int m);
  10. int Number_Days_Of_Month(int y, int m);
  11. void Print_Version();
  12. void Print_Head(int y);
  13. void Print_Month(int y, int m);
  14. void Print_Month_Head(int m);
  15.  
  16.  
  17. void main ()
  18. {
  19. Print_Version();
  20. int year;
  21. cin >> year;
  22.  
  23. Print_Head(year);
  24. for(int i=1; i<=12; i++){
  25. Print_Month(year, i);
  26. }
  27. cout << "bye";
  28. }
  29.  
  30. void Print_Version()
  31. {
  32. cout << "Welcome \n";
  33. }
  34.  
  35. void Print_Head(int y)
  36. {
  37. cout << " " << y << endl;
  38. cout << "==================================================\n";
  39. }
  40.  
  41. void Print_Month(int y, int m)
  42. {
  43. Print_Month_Head(m);
  44. int firstday, number_days;
  45. firstday = First_Day_Of_Month(y,m);
  46. number_days = Number_Days_Of_Month(y,m);
  47. cout << " ";
  48. for (int k=0; k<firstday; k++)
  49. cout << " ";
  50. for (int i = 1; i<number_days; i++){
  51. cout << setw(5) << i;
  52. if ((i + firstday)%7 == 0){
  53. cout << endl;
  54. cout << " ";
  55. }
  56. }
  57. }
  58.  
  59. int First_Day_Of_Month(int y, int m)
  60. {
  61. return 2;
  62. }
  63.  
  64. int Number_Days_Of_Month(int y, int m)
  65. {
  66. if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
  67. {
  68. return 32;
  69. }
  70. else if (m == 4 || m == 6 || m == 9 || m == 11)
  71. {
  72. return 31;
  73. }
  74. else
  75. return 29;
  76. }
  77.  
  78. bool IsLeapYear(int y)
  79. {
  80.  
  81. void Print_Month_Head(int m)
  82. {
  83.  
  84.  
  85. if (m == 1)
  86. {
  87. cout << "\n January Sun Mon Tue Wed Thu Fri Sat\n";
  88. }
  89. else if (m == 2)
  90. {
  91. cout << "\n February Sun Mon Tue Wed Thu Fri Sat\n";
  92. }
  93. else if (m == 3)
  94. {
  95. cout << "\n March Sun Mon Tue Wed Thu Fri Sat\n";
  96. }
  97. else if (m == 4)
  98. {
  99. cout << "\n April Sun Mon Tue Wed Thu Fri Sat\n";
  100. }
  101. else if (m == 5)
  102. {
  103. cout << "\n May Sun Mon Tue Wed Thu Fri Sat\n";
  104. }
  105. else if (m == 6)
  106. {
  107. cout << "\n June Sun Mon Tue Wed Thu Fri Sat\n";
  108. }
  109. else if (m == 7)
  110. {
  111. cout << "\n July Sun Mon Tue Wed Thu Fri Sat\n";
  112. }
  113. else if (m == 8)
  114. {
  115. cout << "\n August Sun Mon Tue Wed Thu Fri Sat\n";
  116. }
  117. else if (m == 9)
  118. {
  119. cout << "\n September Sun Mon Tue Wed Thu Fri Sat\n";
  120. }
  121. else if (m == 10)
  122. {
  123. cout << "\n October Sun Mon Tue Wed Thu Fri Sat\n";
  124. }
  125. else if (m == 11)
  126. {
  127. cout << "\n November Sun Mon Tue Wed Thu Fri Sat\n";
  128. }
  129. else
  130. {
  131. cout << "\n December Sun Mon Tue Wed Thu Fri Sat\n";
  132. }
  133.  
  134.  
  135.  
  136.  
  137. }
Last edited by raydogg57 : Jan 28th, 2007 at 6:29 pm.
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 8:14 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC