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

Recommended Answers

All 2 Replies

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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.