Question Create a star in VB2008

kaisermhi

Member
Joined
Sep 22, 2010
Messages
8
Programming Experience
Beginner
how to write a console application by using nested For.. Next loops to generate the star design as per below picture. star design.JPG

Thanks in advance.
 
that's a triangle...

and why not give some type of effort... this sounds like a weird 'easy homework question' or something. I say this because, why a for loop? You don't need a for loop to do that, but you're asking for one, which leads me to believe you're required to use a for loop, which leads me to believe this is homework.

So why not show us what you've done, and then ask a question that can let us help you... instead of just doing it for you.
 
What have you done for this question so far?

Do you have ANYTHING written?

Take a try at it, show us what you have, and ask a more specific question.
 
It's so easy, i did it in like two seconds. Just make your loop, then each time it loops it does a math equation to get the right amount of characters to output to the console.

At least come up with something to show us what you have done. Don't expect to have the code handed to you. You will never learn that way.
 
It's so easy, i did it in like two seconds. Just make your loop, then each time it loops it does a math equation to get the right amount of characters to output to the console.

At least come up with something to show us what you have done. Don't expect to have the code handed to you. You will never learn that way.

This is what I had done:

Module starreverse
VB.NET:
    Sub Main()
        Dim snum As String, num, s As Integer
        Console.Write("Enter an odd number up to 13:  ")
        snum = Console.ReadLine
        Integer.TryParse(snum, num)
        If num Mod 2 = 0 Then num += 1 'verify odd number
        If num > 13 Then num = 13 'restrict size to fit on screen

        For x As Integer = 1 To num Step 2
            s = (num + x) \ 2
            Console.Write(Space(s))
            For y As Integer = 1 To x
                Console.Write("*")
            Next y
            Console.WriteLine()
        Next x

        For x As Integer = num - 2 To 1 Step -2
            s = (num + x) \ 2
            Console.Write(Space(s))
            For y As Integer = 1 To x
                Console.Write("*")
            Next y
            Console.WriteLine()
        Next x
        Console.ReadLine()
    End Sub

End Module
 
Last edited by a moderator:
Back
Top