這裏是我的代碼循環不循環和第二如果沒有Iffing
Module Module1
Sub Main()
Dim yob As Integer
System.Console.WriteLine("If you would as be kind as to input your year of birth then I will tell you how old you are")
loops:
Try
yob = Int32.Parse(Console.ReadLine())
Catch ex As SystemException
Console.WriteLine("that is not a number, try again.")
GoTo loops
Finally
End Try
Do Until yob > 0 And yob < DateTime.Today.Year
Loop
If yob < 0 Or yob > DateTime.Today.Year Then
Console.WriteLine("You entered a number that is either zero or a date in the future.")
Console.WriteLine("You can't be born in the future. C'mon son")
Console.WriteLine("Try again")
End If
Dim Age = DateTime.Today.Year - yob
Console.WriteLine("You are " & Age & " years old")
If Age > 100 Then
Console.WriteLine("You are were born over a 100 years ago and little is known about that time since there was no Facebook, Twitter or Instagram for people to log their every")
Console.WriteLine(" thought, action, emotion, or take pictures of their food before this time")
Console.ReadKey()
End If
If Age > 90 Then
Console.WriteLine("You were born in the 20s")
Console.WriteLine("In this decade Halloween was born. The first Halloween celebration in America took place in Anoka, Minnesota in 1921. ")
Console.ReadKey()
End If
End Sub
End Module
直到我在try catch塊我的循環將運行正常添加一個goto。現在它不會,如果你輸入比2014年更大的一年,它只是坐在他們的身上。 我的另一個問題是,我的第二如果不起作用。如果你在一年中使你的年齡大於90歲,那麼它不會做任何事情,並且程序會在沒有執行If語句的情況下結束。 有什麼不對的想法?
你有調試嗎?設置一個斷點,比較它實際上做什麼與你認爲它會做什麼 – Plutonix
對不起,我對此很陌生,這是我的第一個編程課程。該程序編譯得很好,它只是沒有做它應該做的。 –
多數民衆贊成是**爲什麼**我們調試 - 修復邏輯錯誤;知道如何**代碼實際**運行結果在未來較少類似的錯誤 – Plutonix