我不太明白为什么我的代码不起作用而且对于1900年(不是闰年),它仍然显示29天
Dim Month, Year As Integer
Dim X, Y As Single
Console.WriteLine("Which month is it?")
Month = Console.ReadLine()
Console.WriteLine("Which year is it?")
Year = Console.ReadLine()
Select Case Month
Case 4, 6, 9, 11
Console.WriteLine("Number of days is 30.")
Case 2
If Year Mod 100 = 0 Then
X = Year Mod 400
Else
Y = Year Mod 4
End If
If X = 0 Or Y = 0 Then
Console.WriteLine("The number of days is 29.")
Else
Console.WriteLine("The number of Days is 28.")
End If
Case Else
Console.WriteLine("Number of days is 31")
End Select
Console.ReadLine()
答案 0 :(得分:0)
我摆脱X
和Y
- 正如我在评论中所说的那样,其中一个总是等于零,因为你的代码只会改变一个。虽然您可以使If
关于100年规则的两个分支设置相同的变量,然后检查0
,我会只需将所有逻辑直接放在一个If
中:
If Year Mod 400 = 0 Or (Year Mod 4 = 0 And Not Year Mod 100 = 0) Then
Console.WriteLine("The number of days is 29.")
Else
Console.WriteLine("The number of Days is 28.")
End If