Hey there guys,
First time poster here, so I apologize for being a rookie. This is my first VB class and im having a hard time with For-Next loops.
The question assigned is as follows:
Request and odd number, and display a triangle similar to this:
***** **** *** ** *
with the input number of stars in the front row.
My code so far is as follows:
Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click Dim numStars As Integer lstOutput.Items.Clear() numStars = CInt(InputBox("Enter amount of stars: (Odd numbers only)")) If numStars Mod 2 = 0 Then MsgBox("Not an odd number. Please try again.", , Nothing) Else ShowBox(numStars) End If End Sub Sub ShowBox(ByVal numStars As Integer) Dim row As String = " " For i As Integer = numStars To 1 Step -1 row &= "*" lstOutput.Items.Add(row) Next End Sub
As you can see it is only an issue of having the maximum number of stars on top, rather than at the bottom. I figure the issue is just reworking the loop, or adding another nested loop, but I am having a hard time finding the solution.