Yet another Calendar Program.

This is a discussion on Yet another Calendar Program. within the C Programming forums, part of the General Programming Boards category; If 01/01/1900 is monday...then find the day on every Jan 1st of the year entered through the keyboard. I have ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    47

    Yet another Calendar Program.

    If 01/01/1900 is monday...then find the day on every Jan 1st of the year entered through the keyboard.

    I have been thinking quite a lot about this program..trying to search around with some logic...but no!

    My level is too low to understand arrays, functions..etc.

    I've just done a couple of chapter..if-else and stuff..and I am given this program.

    Trying to figure out what is the logic like to find out what is the day after 365 days..

    Then the leap year thing is causing a problem..cuz the logic would change then..

    Still thinking..but no luck so far..

    Finally decided to post and get some help.

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    This link explains how to do it for any date of the year, might only
    be accurate for 20th century, although the document doesn't
    mention that, I saw such a calculation method before and it was
    only accurate for that century. There's actually a good few
    methods of doing this - here's a second:

    http://www.tondering.dk/claus/cal/no...00000000000000

    http://quasar.as.utexas.edu/BillInfo/doomsday.html
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Okay..I found what needs to be done..but still not able to convert it into C Code.

    I figured out that the closest Doomsday to the required Date is Jan 31 - 1/31 (2/0).
    For 19xx, the Doomsday is Wednesday.

    Now to calculate the doomsday for that particular year, the following procedure is to be followed

    xx as in 19xx

    The xx can be found out by
    19xx%100

    Q=xx/12
    R=xx%12
    S=R/4

    Doomsday=Q+R+S

    Now, we have to count Q+R+S number of days ahead of Wednesday. If this Doomsday calculation results in a number less than 7, then there won't be a problem.
    But if it is a number greater than 7, then how can i write the code so that the addition starts again from 1?

    Like 3+7 should be 3!

    I hope I am going in the right direction!

  4. #4
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Also, just thought about the Leap Year thing.
    There has to be two conditions.

    If it is a leap year, then doomsday falls on 2/1 (2-Feb...1-1st Day)

    If it is not, then it falls on 1/31.

    I suppose I will have to use an if-else to sort out the two conditions.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    I am still stuck on this one..cannot really think any further..

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Well start by posting some simple code, say

    - input a year (say 1976)
    Then your program outputs
    - whether that year is a leap year
    - how many leap years there have been since 1900


    // 19xx%100
    int year = 1976;
    int xx = year % 100;

    int Q=xx/12;
    int R=xx%12;
    int S=R/4;

    Got it yet?

    Add plenty of printf() statements to print each result as you go along, and check what you're printing is matching your paper calculations.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    I was already done with that...

    What I am looking for is the logic that would print what Day is it on the First of January of the entered year.

  8. #8
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    You mean like, having got a number between 1 and 7 (or 0 and 6), you do
    if ( d == 0 ) printf("Monday\n" );

    etc etc

    You could use a switch/case for that.

    Or maybe even an array of strings, indexed by day number.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  9. #9
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Nope..just if-else, Logical and/ or conditional operators.

    And also, The year 19xx is to be entered through the keyboard.

    The program should find out what day is it on the 1st January of the entered year.

  10. #10
    Registered User
    Join Date
    Jan 2006
    Posts
    47
    Finally I managed to solve the problem using if- else...

    The Program can be found at the following Link:

    Calendar Program - Detecting the day on 1st Jan between 1900-19xx using if-else

    I was quite surprised to see that there ain't no Doomsday thing involved!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  2. Need help with my program...
    By Noah in forum C Programming
    Replies: 2
    Last Post: 03-11-2006, 06:49 PM
  3. my server program auto shut down
    By hanhao in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-13-2004, 09:49 PM
  4. calendar program
    By dharmastum in forum C Programming
    Replies: 3
    Last Post: 01-25-2002, 04:35 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21