0

i have a question about the logic about the calendar question. I have to make a calendar, so user inputs a month (number 1-12) and a date, and the output is suppose to be: Friday, January 1, 2010. Suppose to be written in just simple c, no arrays or anything, only while or like for loops and stuff. I got it done and everything works fine, but the code is like 550 lines. my logic is as follows
input month m
input date n
then if checks if m==1, then it goes to while date>=1 (coz i only did for the days for the first week so if n=1 - then its monday, else if 2-tuesday......else if 7-sunday; break; ), and if 29 entered, at the end of the loop "else n=n-7" so it goes down by 7 untill it reaches the 1-7 numbers..
so exact the same thing for the next 11 months of 2010, the only problem is the every month starts with a different day of the week, theres like 2 or 3 month start with the same day, so i did if n==1 || n==3 then the days of the week as follows..
so my question is there any shorter way to do it?
thanks in advance

Edited by Unidennn: n/a

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Unidennn
1

Keep track of the number of days per year. If you need March 12, that would be 31+28+12 (Jan+Feb+Mar). Now you can use your 7 days to get the days of the week. The % (mod) operator can help here.

0

lol yea thats right, i didnt think of that, im gonna try it now and see if i get it done that way :)
thanks

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.