У меня возникли проблемы с моим кодом возвращающей -1, если isPicked
находится в моем GetWoodTypes
метода False
, мой если заявление полностью игнорируется, и я не могу найти проблему в коде , если кто-то может помочь, что было бы здоровоVb.net Метод не возвращает значение
Public Class Class1
Shared Sub Main()
Dim woodType() As String = {"Pine", "Oak", "Elm"}
Dim woodPrice() As Integer = {100, 140, 200}
Dim nameIndex As Integer = 0
nameIndex = GetWoodTypes(woodType, woodPrice)
Dim Quantity As Integer = 0
Dim basePrice As Integer = 0
Quantity = GetDrawerQtys()
basePrice = GetPrices(woodType, woodPrice, nameIndex, Quantity)
If nameIndex = -1 Then
Console.Write("You have made the wrong selection, Please try Again")
Console.ReadLine()
Else
DisplayResults(Quantity, woodType, woodPrice, basePrice, nameIndex)
End If
End Sub
Public Shared Function GetWoodTypes(values() As String, Price() As Integer)
Console.Write("Please select the type of wood you would like to purchase: Pine,Oak,Elm ")
Dim Selectedwood As String = Console.ReadLine()
Dim ispicked As Boolean = False
Dim location As Integer = 0
For i As Integer = 0 To values.Count - 1
If Selectedwood.ToLower = values(i).ToLower Then
ispicked = True
location = i
End If
Next i
If ispicked Then
Console.WriteLine("Thank you for selection, you have picked {0} at {1} ", values(location), Price(location))
Return location
Else
Console.Write("Sorry")
Return -1
End If
End Function
Public Shared Function GetDrawerQtys()
Console.WriteLine(" How Many Drawers do you want ")
Dim DrawerQty As Integer = Console.ReadLine()
Return DrawerQty
End Function
Public Shared Function GetPrices(types() As String, price() As Integer, location As Integer, Quantity As Integer)
Console.Write("You have ordered a {0} with {1} drawers at {2} each ", types(location), Quantity, price(location))
Dim Amount As Integer = (Quantity * 30) + price(location)
Return Amount
End Function
Public Shared Sub DisplayResults(Quantity As Integer, type() As String, price() As Integer, basePrice As Integer, location As Integer)
Console.WriteLine("Hello you have purchased {0} {1} at {2} your total is {3} ", Quantity, type(location), price(location), basePrice)
Console.ReadLine()
End Sub
End Class
У вас есть 2 хороших ответа. Если один из них ответил на ваш вопрос, правильная вещь - щелкнуть галочку. [Тур] – user3697824