Jump to content

Leap Year program

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
Gz1987

Gz1987

    Newbie

  • Members
  • Pip
  • 9 posts
By definition a leap year is any year that is divisible by 4. However if a year is a century year it is only a leap year if it is divisible by 400.

I believe i need a If statement in this program? please help this n00b out :]

EDIT: also he program is going to keep going until a sentinel is entered.

To my knowledge, sentinel is a value that you set to make the program start? is there any more info you can give me? i am new to programming.

#2
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
int IsLeapYear(int iYear)
{
    if(iYear % 400 == 0) return 1;
    else if(iYear % 100 == 0) return 0;
    else if(iYear % 4 == 0) return 1;
    else return 0;
}


#3
G_Morgan

G_Morgan

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 537 posts
A sentinel is a predefined value (usually one that cannot possible be correct input for the program) that is used to exit a loop. Basically:


read value;

while(value != sentinel) {

    do calculation;

    read value;

}



#4
Gz1987

Gz1987

    Newbie

  • Members
  • Pip
  • 9 posts
Thanks for the reply
Now i have to add to this program to calculate the days between two dates. I will post my code later once i finish it. probably gonna need some help.