martes, 22 de marzo de 2011

Ejercicio1. Simulación de una compra de una tienda

Module Module1
Private opcion As Int16 = 0
Private menu() As String = {"Salir", "mercancia 1", "mercancia 2", "mercancia 3", "mercancia 4", "mercancia 5"}
Private precio() As Double = {0, 1.67, 24.8, 3.8, 4.54, 5.9}
Sub Main()
Dim listMercancia As New Generic.List(Of Int16)
Dim listTotal As New Generic.List(Of Double)
Dim Total As Double = 0
Dim cantidad As Double = 0
While OpcionesMenu() > 0
listMercancia.Add(opcion)
Console.Write("Ingrese la cantidad del producto: ")
cantidad = Double.Parse(Console.ReadLine())
listTotal.Add(precio(opcion) * cantidad)
Console.Clear()
End While
Console.Clear()
For g As Int16 = 0 To listMercancia.Count - 1
Console.WriteLine(String.Format("{0}{1}{2}", menu(listMercancia(g)), vbTab, Strings.FormatCurrency(listTotal(g))))
Total += listTotal(g)
Next
Console.WriteLine(String.Format("El total a pagar es: {0}", Strings.FormatCurrency(Total)))
Console.Read()
End Sub
Private Function
OpcionesMenu() As Int16
Console.WriteLine(vbLf & "Seleccione el numero de la mercancia" & vbLf)
For g As Int16 = 0 To menu.Length - 1
Console.WriteLine(String.Format("{0}- {1} {2}", g, menu(g), IIf(Strings.FormatCurrency(precio(g)) = Strings.FormatCurrency(0), "", Strings.FormatCurrency(precio(g)))))
Next
opcion = Val(Console.ReadLine())
Return opcion
End Function
End Module