User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,564 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,522 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
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

  #7  
Jan 28th, 2007
Thanks Ravalon! What I actually did instead was:

  1. int Leapyear;
  2. Leapyear = IsLeapYear(y);
  3. else if (Leapyear == 1)

and the code works just fine! Now the only (and biggest) kink I have left in my code is determining the first day of every month. The information I was given was:

First day of January in 1800 was a Wednesday. Then adding up all the days up to this given year(including extra days from leap years) and finding the remainder of 7. this supposedly helps me determine the day of the week for the first day of every month. I am unclear as to how to type a code for something like this, it seems like it would be a lot of 'if' statements. I am going to try and sit and think about this but I was wondering if you could give me some ideas to work with while developing this, because it is giving me a lot of trouble. Thanks a lot! As always, my code is posted below:

  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. bool IsLeapYear(int y);
  12. void Print_Version();
  13. void Print_Head(int y);
  14. void Print_Month(int y, int m);
  15. void Print_Month_Head(int m);
  16.  
  17.  
  18. void main ()
  19. {
  20. Print_Version();
  21. int year;
  22. cin >> year;
  23.  
  24. Print_Head(year);
  25. for(int i=1; i<=12; i++){
  26. Print_Month(year, i);
  27. }
  28. cout << "\nGoodbye! \n";
  29. }
  30.  
  31.  
  32. //Functions
  33.  
  34. void Print_Version()
  35. {
  36. cout << "Please Enter any Year After 1799 \n";
  37. }
  38.  
  39. void Print_Head(int y)
  40. {
  41. cout << " " << y << endl;
  42. cout << "==================================================\n";
  43. }
  44.  
  45. void Print_Month(int y, int m)
  46. {
  47. Print_Month_Head(m);
  48. int firstday, number_days;
  49. firstday = First_Day_Of_Month(y,m);
  50. number_days = Number_Days_Of_Month(y,m);
  51. cout << " ";
  52. for (int k=0; k<firstday; k++)
  53. cout << " ";
  54. for (int i = 1; i<=number_days; i++){
  55. cout << setw(5) << i;
  56. if ((i + firstday)%7 == 0){
  57. cout << endl;
  58. cout << " ";
  59. }
  60. }
  61. }
  62.  
  63. bool IsLeapYear(int y)
  64. {
  65. if (y%400 == 0)
  66. {
  67. return 1;
  68. }
  69. else if (y%4 == 0 && y%100 != 0)
  70. {
  71. return 1;
  72. }
  73. else
  74. return 0;
  75. }
  76.  
  77. int First_Day_Of_Month(int y, int m)
  78. {
  79. return 2;
  80. }
  81.  
  82. int Number_Days_Of_Month(int y, int m)
  83. {
  84. int Leapyear;
  85. Leapyear = IsLeapYear(y);
  86. if (m == 1 || m == 3 || m == 5 || m == 7 || m == 8 || m == 10 || m == 12)
  87. {
  88. return 31;
  89. }
  90. else if (m == 4 || m == 6 || m == 9 || m == 11)
  91. {
  92. return 30;
  93. }
  94. else if (Leapyear == 1)
  95. {
  96. return 29;
  97. }
  98. else
  99. {
  100. return 28;
  101. }
  102.  
  103. }
  104.  
  105. void Print_Month_Head(int m)
  106. {
  107.  
  108. if (m == 1)
  109. {
  110. cout << "\n January Sun Mon Tue Wed Thu Fri Sat\n";
  111. }
  112. else if (m == 2)
  113. {
  114. cout << "\n February Sun Mon Tue Wed Thu Fri Sat\n";
  115. }
  116. else if (m == 3)
  117. {
  118. cout << "\n March Sun Mon Tue Wed Thu Fri Sat\n";
  119. }
  120. else if (m == 4)
  121. {
  122. cout << "\n April Sun Mon Tue Wed Thu Fri Sat\n";
  123. }
  124. else if (m == 5)
  125. {
  126. cout << "\n May Sun Mon Tue Wed Thu Fri Sat\n";
  127. }
  128. else if (m == 6)
  129. {
  130. cout << "\n June Sun Mon Tue Wed Thu Fri Sat\n";
  131. }
  132. else if (m == 7)
  133. {
  134. cout << "\n July Sun Mon Tue Wed Thu Fri Sat\n";
  135. }
  136. else if (m == 8)
  137. {
  138. cout << "\n August Sun Mon Tue Wed Thu Fri Sat\n";
  139. }
  140. else if (m == 9)
  141. {
  142. cout << "\n September Sun Mon Tue Wed Thu Fri Sat\n";
  143. }
  144. else if (m == 10)
  145. {
  146. cout << "\n October Sun Mon Tue Wed Thu Fri Sat\n";
  147. }
  148. else if (m == 11)
  149. {
  150. cout << "\n November Sun Mon Tue Wed Thu Fri Sat\n";
  151. }
  152. else
  153. {
  154. cout << "\n December Sun Mon Tue Wed Thu Fri Sat\n";
  155. }
  156.  
  157. }
Reply With Quote  
All times are GMT -4. The time now is 5:45 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC