如何让它打印我的选择和更改到期?

时间:2017-05-11 03:21:22

标签: vb.net

我希望它告诉我我的选择以及我放入机器的剩余金额

Module Module1

    Sub Main()
        Dim moneyInserted As Double
        Dim selectedSoda As String
        Dim changedue As Double = 0.5


        Console.WriteLine("Insert Money")
        moneyInserted = Console.ReadLine()
        Console.WriteLine("Type A for Crystal Clear Pepsi, B for New Coke, and C for OK Soda")
        selectedSoda = Console.ReadLine()
        Dim theSoda As String = sodaMachine(selectedSoda, moneyInserted, changedue)
        Console.WriteLine("Your choice is {0}", sodaMachine(selectedSoda,moneyInserted, changedue))
        Console.ReadLine()

    End Sub

    Function sodaMachine(ByVal selection As String, ByVal money As Double, ByVal change As Double) As String
        If money >= 0 Then
            Return (money - change)
            If selection = "A" Or selection = "a" Then
                Return "Crystal Clear Pepsi"

            ElseIf selection = "B" Or selection = "b" Then
                Return "New Coke"

            ElseIf selection = "C" Or selection = "c" Then
                Return "OK Soda"
            Else
                Return "Invalid Selection"
            End If
        Else
            Return "Not enough money"
        End If

    End Function

End Module

1 个答案:

答案 0 :(得分:0)

你可以让sodaMachine()返回Tuple

Dim retval = New Tuple(Of Double, String)()
retval.Item1 = (money - change)
retval.Item2 = "Crystal Clear Pepsi"

Return retval

https://msdn.microsoft.com/en-us/library/system.tuple(v=vs.110).aspx