good afternoon I have the following problem, the program is already solved for the most part, from a vector of 10 values, it shows the original vector, the average, if it is failed or not and the smaller number, the latter does not reflect the value yes not a 0, can you help me?, I already changed to another for, and it does not give me the minor, instead if I change that sign it does give me the major
Public Class Form1
Dim vector(10), i As Integer
Dim Sum As Double
Dim Prom As Double
Dim cont As Double
Dim min As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = ""
Label2.Text = ""
Label3.Text = ""
Label4.Text = ""
For i = 1 To 10
Label1.Text = Label1.Text & vector(i) & " "
Sum += vector(i)
cont += 1
Next
Prom = Sum / cont
For i = 1 To 10
If min > vector(i) Then
min = vector(i)
End If
Next
If Prom > 5 Then
Label3.Text = "Aprobado"
Else
Label3.Text = "reprobado"
End If
Label2.Text = Label2.Text & Prom & " "
Label4.Text = Label4.Text & min & " "
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i = 1 To 10
vector(i) = InputBox("Ingresa el numero del vector", "Datos Vector", 0)
Next
End Sub
End Class
introducir el código aquí
And if you try to call Min inside the function instead of at initialization.
Just assign the variable above this line
The problem is that, when you declare the variable
min
, it is, by default, equal to 0, and therefore the conditionIf min > vector(i)
would be fulfilled only if itvector(i)
is negative.What you can do is initialize the variable
min
to a value high enough that it will be assigned whenever it finds the first element of the array. For example, if you expect values between 1 and 100, you could initialize it to 101, for example, you can do something like this: