我的 VB.NET 程序给了我两个错误:
- 当我输入负值或 0 时它不会中断。
- 它没有显示总值。
谁能帮我解决这个问题?
Enter deposit amount: 300
Another (y or n)? y
Enter deposit amount: -1
Amount cannot be zero or negative.
我的代码:
Module Module1
Sub Main()
Dim userResponse As Char
Dim depositAmount As Decimal
Dim totalDeposits As Decimal
Dim depositCount As Integer
Dim averageDeposit As Decimal
depositCount = 0
totalDeposits = 0
While Not (userResponse = "n")
Console.WriteLine("Enter Desposit Amount:")
If (depositAmount < 0 And depositAmount = 0) Then
Console.WriteLine("Amount cannot be zero or negative.")
Else
depositAmount = Console.ReadLine()
Console.WriteLine("Another (y or n)?")
userResponse = Console.ReadLine()
totalDeposits = totalDeposits + depositAmount
depositCount = depositCount + 1
averageDeposit = totalDeposits / depositCount
End If
End While
Console.WriteLine(" Total deposits: " + totalDeposits.ToString)
Console.WriteLine(" Number of deposits: " + depositCount.ToString)
Console.WriteLine("Average deposit: " + averageDeposit.ToString)
End Sub
End Module