Day number program

Discussion in 'C' started by songweaver, Mar 25, 2009.

  1. songweaver

    songweaver New Member

    Joined:
    Mar 3, 2009
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    I need help with Day Number program, I have already got the Leap Year subprogram to work, but I need help with the day number program as far as how to set it up and incorporate the leap year program. Here is the scenario and below that the leap year subprogram.

    Write a function dayNumber that returns the day number (1 to 366) in a year for a date that is provided as input data. Your function should accept the month (1 through 12), day, and year as integers. As an example. For example, January 1, 1994 is day one. December 31 2004 is day 366 because its a leap year. A leap year is divisible 4, except that any year is divisible by 100 is a leap year only if it is divisible by 400. Write a second function that returns true if its argument, a year, is a leap year.

    Also I cannot use loops or arrays of any sort. Just calling on these subprograms. Any help would be much appreciated!

    Code:
    #include <iostream>
    
    using namespace std;
    
    bool checkLeapYr(int year)
    {
     if ((year%4==0) && (year %100!= 0) || (year%400 == 0))
    
     {
      return true;            
      
     }
     else
     { 
     return false;
    }        
    }
    
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Well, how would you do it on paper? What day number is 14th March 2003? 14th March 2004?
    If you can't use arrays then you'll have to use fixed constants in the program, so you might want to consider a daysInMonth() function that takes the month and year and returns the number of days in that month (obviously it only needs the year for February).
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice