I have a code in which letters and numbers are entered in an array.
I have 2 functions:
- To verify that the letters entered are not vowels.
- To verify that the entered number is even.
To find the vowel I have problems, it doesn't work for me with 2 vowels and with the rest it does. If I write some consonants it also generates an error.
Sub Main()
Dim arreglo(6) As Char
CrearArreglo(arreglo)
End Sub
Function CrearArreglo(ByRef arreglo() As Char) As Char()
Console.WriteLine("Ingresar 3 letras que no sean VOCALES")
For i As UShort = 0 To 2 Step 1
arreglo(i) = Console.ReadLine()
ValidarLetraVocal(arreglo, i)
Console.ReadLine()
Next
Console.WriteLine("Ingresar 4 numeros que sean PARES")
For x As UShort = 2 To 5 Step 1
arreglo(x) = Console.ReadLine()
ValidarNumeroPar(arreglo, x)
Next
Return arreglo
End Function
Function ValidarLetraVocal(ByRef arreglo() As Char, ByRef i As UShort) As Boolean
For i = 0 To arreglo.Length - 1
Select Case arreglo(i)
Case "A", "a", "E", "e", "I", "i", "O", "o", "U", "u"
Console.WriteLine("ERROR, ES UNA VOCAL!")
Return False
End Select
Next
Return True
End Function
Function ValidarNumeroPar(ByRef arreglo() As Char, ByRef x As UShort) As Boolean
Dim buscarValor As String
Dim aux As UShort
aux = Convert.ToUInt16(arreglo(x))
For Each buscarValor In arreglo
''Microsoft.VisualBasic.AscW
If aux Mod 2 = 0 Then
Return True
End If
Next
Console.WriteLine("ERROR, ES IMPAR!")
Return False
End Function
If you declare the array with a length of 6 (
Dim arreglo(6) As Char
), you can't put 7 elements (3 letters + 4 numbers) in it, so it should be:Then you make a mistake in the function
CrearArreglo
, in capturing the numbers, because you are overwriting position 2 of the array, it should be between position 3 and 6: