我正在尝试使用Visual Basic.NET实现一个简单的计算输出总价
我想阅读原价和运费重量,然后在计算中使用它。问题是, 当我输入任何值时,两个变量都只返回第一个数字
例如,如果输入23,则返回2
Dim originalPrice As Double
Dim commissionPrice As Double
Dim shippingWeight As Double
Dim totalPrice As Double
Console.Write("Enter Original Price: ")
originalPrice = Double.Parse(Console.ReadLine(originalPrice))
Console.Write("Enter Shipping Weight: ")
shippingWeight = Double.Parse(Console.ReadLine(shippingWeight))
shippingWeight = shippingWeight * 7
If (originalPrice + shippingWeight >= 200) Then
commissionPrice = (originalPrice + shippingWeight) * 0.03
Else
commissionPrice = 5
End If
totalPrice = commissionPrice + originalPrice + shippingWeight
Console.WriteLine(originalPrice)
Console.WriteLine(commissionPrice)
Console.WriteLine(shippingWeight)
Console.WriteLine(totalPrice)
答案 0 :(得分:1)
我认为您的问题是您将变量传递给Console.read()
以这种方式应该工作。
Dim originalPrice As Double
Dim commissionPrice As Double
Dim shippingWeight As Double
Dim totalPrice As Double
Console.Write("Enter Original Price: ")
originalPrice = Double.Parse(Console.ReadLine())
Console.Write("Enter Shipping Weight: ")
shippingWeight = Double.Parse(Console.ReadLine())
shippingWeight = shippingWeight * 7
If (originalPrice + shippingWeight >= 200) Then
commissionPrice = (originalPrice + shippingWeight) * 0.03
Else
commissionPrice = 5
End If
totalPrice = commissionPrice + originalPrice + shippingWeight
Console.WriteLine(originalPrice)
Console.WriteLine(commissionPrice)
Console.WriteLine(shippingWeight)
Console.WriteLine(totalPrice)
Console.Read()