|
-
Oct 29th, 2008, 06:32 PM
#1
Thread Starter
New Member
Please help.
I am trying to write a program to determine if a year is a leap year or not. It is driving me nuts, i know nothing about leap years. Here is the question.
"The current calendar, called the gregorian calendar, was introduced in 1582. Every year divisible by four was declared to be a leap year, with the exception of the years ending in 00(that is, those divisible by 100) and not divisible by 400."
i cant figure out how to even go about it, here is as far as i got with my coding.
Code:
Public Class Form1
Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
Dim year, value, value2 As Double
year = CDbl(txtYear.Text)
value = year / 100
value2 = value / 4
MessageBox.Show(CStr(value2))
End Sub
End Class
-
Oct 29th, 2008, 06:35 PM
#2
Re: Please help.
try this:
vb Code:
MsgBox(Date.IsLeapYear(1582))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 29th, 2008, 06:42 PM
#3
Thread Starter
New Member
Re: Please help.
thanx alot dude, i never would have thought of that
-
Oct 30th, 2008, 11:11 AM
#4
Re: Please help.
If this is homework, your teacher may not accept Paul's solution since the purpose of the exercise is to help you learn how to turn an algorithm into code.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Oct 30th, 2008, 11:37 AM
#5
Re: Please help.
you can calculate leap years easily, using the specifications you provided in post #1:
vb Code:
Dim Y As Integer = CInt(txtYear.Text)
If Y Mod 4 = 0 And Not Y Mod 100 = 0 Or Y Mod 4 = 0 And Y Mod 400 = 0 Then
'is a leap year
End If
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 30th, 2008, 11:41 AM
#6
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|