jeudi 26 mars 2015

I need to design a program which output the specific day of the week given the date using vb console(VB net)

Module Module1



Sub Main()
Dim N, d, m, y, T As Integer

Console.Write("Enter the date(DD): ")
Console.ReadLine()
Console.Write("Enter the month(MM): ")
Console.ReadLine()
Console.Write("Enter the year(YY): ")
Console.ReadLine()


N = d + 2 * m + (3 * (m + 1) / 5) + y + (y / 4) - (y / 100) + (y / 400) + 2
T = N Mod 7 - 1
If T = 1 Then
Console.Write("The day is Monday")
Console.ReadLine()
ElseIf T = 2 Then
Console.Write("The day is Tuesday")
Console.ReadLine()
ElseIf T = 3 Then
Console.Write("The day is Wednesday")
Console.ReadLine()
ElseIf T = 4 Then
Console.Write("The day is Thursday")
Console.ReadLine()
ElseIf T = 5 Then
Console.Write("The day is Friday")
Console.ReadLine()
ElseIf T = 6 Then
Console.Write("The day is Saturday")
Console.ReadLine()
ElseIf T = 7 Then
Console.Write("The day is Sunday")
Console.ReadLine()

End If
End Sub


End Module


Depending on the formula, i suppose that it should work but it's not. It's not giving me the right day. Maybe because we also need to calculate the leap year in it? I need simple vb net code.


Aucun commentaire:

Enregistrer un commentaire