VB.NET プログラムで次の 2 つのエラーが表示されます。
- マイナスの値や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