Post a New Question

c++ programming

posted by on .

Write a program that determines the day number (1 to 366) in a year for a date that is provided as input data. As an example, January 1, 2011 is day 1. December 31, 2010 is a day 365. December 31, 2012 is day 366, since 2012 is a leap year. A year is a leap year if it is divisible by four, except that any year divisible by 100 is a leap year only if it is divisible 400. Your program should accept the month, day and year as integers.

  • c++ programming - ,

    You'll need to first determine if the year is a leap year by the rules given above:

    int isLeap(int year){
    int leap=0;
    if(year divisible by 4)leap=1;
    if(year divisible by 100)leap=0;
    if(year divisible by 400)leap=1;
    return leap;
    }

    Then make an array of cumulative number of days of the previous month, example:
    int cndpm(int n){
    // n=month, 1=january, ...12 = december
    int count[12];
    count[0]=0;
    count[1]=31;
    count[2]=59; // 60 for leap year
    ...
    }
    So for March, cndpm(2) will return the total number of days before March 1st.

    I'll let you think about the rest, and post if you need further help.

  • c++ programming - ,

    LOL I ARE SO COOL

Answer This Question

First Name:
School Subject:
Answer:

Related Questions

More Related Questions

Post a New Question