943,544 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 516
  • C RSS
Sep 23rd, 2008
0

Help with my calendar!

Expand Post »
pls help me with my code! it wont align! T_T
i cant get it to work correctly! pls help guys!
heres the screenshot! the date wont align huhu!




  1.  
  2. #include<stdio.h>
  3. #include<string.h>
  4. #include<conio.h>
  5. int getNumberOfDays(int month,int year)
  6. {
  7. switch(month)
  8. {
  9. case 1 : return(31);
  10. case 2 : if(year%4==0)
  11. return(29);
  12. else
  13. return(28);
  14. case 3 : return(31);
  15. case 4 : return(30);
  16. case 5 : return(31);
  17. case 6 : return(30);
  18. case 7 : return(31);
  19. case 8 : return(31);
  20. case 9 : return(30);
  21. case 10: return(31);
  22. case 11: return(30);
  23. case 12: return(31);
  24. default: return(-1);
  25. }
  26. }
  27. char *getName(int odd)
  28. {
  29. switch(odd)
  30. {
  31. case 0 :return("Sunday");
  32. case 1 :return("Monday");
  33. case 2 :return("Tuesday");
  34. case 3 :return("Wednesday");
  35. case 4 :return("Thursday");
  36. case 5 :return("Friday");
  37. case 6 :return("Saturday");
  38. default:
  39. return("Error in getName() module.Invalid argument passed");
  40. }
  41. }
  42. int getOddNumber(int day,int mon,int year)
  43. {
  44. int res=0,t1,t2,y=year;
  45. year = year-1600;
  46. while(year>=100)
  47. {
  48. res=res+5;
  49. year=year-100;
  50. }
  51. res=(res%7);
  52. t1=((year-1)/4);
  53. t2=(year-1)-t1;
  54. t1=(t1*2)+t2;
  55. t1=(t1%7);
  56. res = res+t1;
  57. res=res%7;
  58. t2=0;
  59. for(t1=1;t1<mon;t1++)
  60. {
  61. t2+=getNumberOfDays(t1,y);
  62. }
  63. t2 = t2+day;
  64. t2 = t2%7;
  65. res = res+t2;
  66. res = res%7;
  67. if(y>2000)
  68. res=res+1;
  69. res = res%7;
  70. return res;
  71. }
  72. char *getWeek(int dd,int mm,int yy)
  73. {
  74. int odd;
  75. if(!(mm>=1 && mm<=12))
  76. {
  77. return("Invalid month value");
  78. }
  79. if(!(dd>=1 && dd<=getNumberOfDays(mm,yy)))
  80. {
  81. return("Invalid date");
  82. }
  83. if(yy>=1600)
  84. {
  85. odd = getOddNumber(dd,mm,yy);
  86. odd=odd%7;
  87. return(getName(odd));
  88. }
  89. else
  90. {
  91. return("Please give year more than 1600");
  92. }
  93. }
  94. void printMonth(int mon,int year,int x,int y)
  95. {
  96. int nod,odd,cnt,d=1,x1=x,y1=y;
  97. if(!(mon>=1 && mon<=12))
  98. {
  99. printf("INVALID MONTH");
  100. getch();
  101. return;
  102. }
  103. if(!(year>=1600))
  104. {
  105. printf("INVALID YEAR");
  106. getch();
  107. return;
  108. }
  109. if(x<=0)
  110. x=wherex();
  111. if(y<=0)
  112. y=wherey();
  113. gotoxy(x,y);
  114. textcolor(RED);
  115. cprintf("S");
  116. textcolor(YELLOW);
  117. cprintf(" M T W T F S");
  118. /* 1234567891234567891234567 */
  119. textcolor(7);
  120. cprintf("");
  121. y++;
  122. nod=getNumberOfDays(mon,year);
  123. odd=getOddNumber(d,mon,year);
  124. switch(odd)
  125. {
  126. case 0 : x=x;
  127. cnt=1;
  128. break;
  129. case 1 : x=x+4;
  130. cnt=2;
  131. break;
  132. case 2 : x=x+8;
  133. cnt=3;
  134. break;
  135. case 3 : x=x+12;
  136. cnt=4;
  137. break;
  138. case 4 : x=x+16;
  139. cnt=5;
  140. break;
  141. case 5 : x=x+20;
  142. cnt=6;
  143. break;
  144. case 6 : x=x+24;
  145. cnt=7;
  146. break;
  147. default :
  148. printf("INVALID DATA FROM THE getOddNumber() MODULE");
  149.  
  150.  
  151.  
  152. return;
  153. }
  154. gotoxy(25,25);
  155. gotoxy(x,y);
  156. printf("%02d",d);
  157. for(d=2;d<=nod;d++)
  158. {
  159. if(cnt%7==0)
  160. {
  161. y++;
  162. cnt=0;
  163. x=x1-4;
  164. }
  165. x = x+4;
  166. cnt++;
  167. gotoxy(x,y);
  168. printf("%02d",d);
  169. }
  170. }
  171. main()
  172. {
  173. char ch='k';
  174. int dd,mm,yy;
  175. while(ch!='0')
  176. {
  177. clrscr();
  178. printf("1.Know the day\n");
  179. printf("2.Print the month\n");
  180. printf("0.EXIT\n");
  181. printf("ENTER YOUR CHOICE :\n");
  182.  
  183.  
  184. flushall();
  185. fflush(stdin);
  186. ch=getche();
  187. clrscr();
  188. switch(ch)
  189. {
  190. case '1':
  191. printf("Enter date (DD MM YYYY) : ");
  192. scanf("%d %d %d",&dd,&mm,&yy);
  193. printf("Day is : %s",getWeek(dd,mm,yy));
  194.  
  195. flushall();
  196. getch();
  197. break;
  198. case '2' :
  199. printf("Enter month and year (MM YYYY) : ");
  200. scanf("%d %d",&mm,&yy);
  201. printf(" ");
  202.  
  203.  
  204. printMonth(mm,yy,-1,-1);
  205. flushall();
  206. getch();
  207. break;
  208. case '0' : exit(0);
  209. }
  210. }
  211. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xcyrus_tan_rx is offline Offline
3 posts
since Sep 2008
Sep 23rd, 2008
0

Re: Help with my calendar!

As I can see, you are calculating the X axies values right, but not the Y axies values. Which dont incrment the values a bit more in the Y axies values to suit your requirnment. The following is the bit og your code which you need to cocentrate on
  1. for(d=2;d<=nod;d++)
  2. {
  3. if(cnt%7==0)
  4. {
  5. y++;
  6. cnt=0;
  7. x=x1-4;
  8. }
  9. x = x+4;
  10. cnt++;
  11. gotoxy(x,y);
  12. printf("%02d",d);
  13. }

ssharish
Last edited by ssharish2005; Sep 23rd, 2008 at 9:59 pm.
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Sep 24th, 2008
0

Re: Help with my calendar!

ok ill try it! thnx forthe help! ^^
Reputation Points: 10
Solved Threads: 0
Newbie Poster
xcyrus_tan_rx is offline Offline
3 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Defining sets
Next Thread in C Forum Timeline: Read character from stdin as they are typed





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC