Counting Number of days from year zero

This is a discussion on Counting Number of days from year zero within the C++ Programming forums, part of the General Programming Boards category; I have to write this function int totDay(int m, int d, int y); The function returns the total number of ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    Question Counting Number of days from year zero

    I have to write this function

    int totDay(int m, int d, int y);
    The function returns the total number of days for the given month, day and year from date zero. The teacher gave us a hint (initialize the total to the number of julian days in given year, then add to the total number of days in each year preceding the given year.)

    This is my julian day function, it works.
    Code:
    int julianDay(int month, int day, int year)
    {
    if (theMonth == 1)
    theJulian = theDay;
    if (theMonth == 2)
    theJulian = theDay + 31;
    if (theMonth == 3) 
    theJulian = theDay + 31 + 28; 
    if (theMonth == 4) 
    theJulian = theDay + 31 + 28 + 31; 
    if (theMonth == 5) 
    theJulian = theDay + 31 + 28 + 31 + 30; 
    if (theMonth == 6) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31; 
    if (theMonth == 7) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31 + 30; 
    if (theMonth == 8) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31 + 30 + 31; 
    if (theMonth == 9) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 1; 
    if (theMonth == 10) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30; 
    if (theMonth == 11) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31; 
    if (theMonth == 12) 
    theJulian = theDay + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
    
    return theJulian;
    }
    what i dont understand to do is the part where it says
    add to total the number of days in each year preceding the given year

    Any ideas?

  2. #2
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    does the teacher mean to add all the days of the preceding year to the number of days in the current year? in other words, a recursive function adding the days from present to 0 ce?

  3. #3
    Unregistered
    Guest
    year has 365 days if it is not leap(?) year then it has 366 days.
    so if the year is 0003 then it would be 365+365+365.

    Check the formula for years in net.

    Does the julian calender has days that not exits or was those
    only in earlier calenders. Check that also.

    ;jackz

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    What if I have a year like 1992 or 2006?

  5. #5
    Unregistered
    Guest
    Use google to search info about julian calender.
    If my quick look was right there are no leap year in julian calender so year 1992 days would be 1992 *365

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 12
    Last Post: 03-07-2011, 12:24 AM
  2. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  3. Number Guessing
    By blacknapalm in forum C Programming
    Replies: 2
    Last Post: 10-01-2008, 01:48 AM
  4. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  5. Counting number from a random file
    By kamisama in forum C Programming
    Replies: 42
    Last Post: 02-22-2005, 04:16 PM

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