Hello.
Im a newbie.
I have been working for hours trying to find out how to make this triangle with stars. I have to make a diamond, octagon, and christmas tree and it's proving tobe VERY difficult. Yes I am very new to this. :o

Anyone? Please help me. You can also IM me on aim if that's easier. GoJuicyCouture

I am unable to copy and paste the code :sad:

Thank you so much if anyone decides to help. I was avoiding any help because I wanted to see if i could actually do this, what is supposed to be easy program, but its too hard for me. I am very frustrated and it's getting late! <3 :rolleyes:

Dani AI

Generated

A compact explanation and working VB.NET examples tied to the original thread: asked about nested For...Next patterns (diamond, octagon, tree) and / gave useful copy/paste tips. The core idea for all of these shapes is the same: an outer loop for rows and inner loops (or repeated strings) for leading spaces and the characters to print. Centered shapes use stars = 2*i - 1 and spaces = n - i; a diamond prints the top half i = 1..n then the bottom half i = n-1..1 to avoid duplicating the center line. A Christmas tree is several stacked isosceles triangles; compute a global base width so every tier centers correctly.

Example VB.NET console code (paste into a Console Application):

Sub Main()
    Dim n As Integer = 5  ' size for triangles/diamond

    ' Left-aligned triangle
    For i As Integer = 1 To n
        Console.WriteLine(New String("*"c, i))
    Next

    ' Centered isosceles triangle
    For i As Integer = 1 To n
        Console.Write(New String(" "c, n - i))
        Console.WriteLine(New String("*"c, 2 * i - 1))
    Next

    ' Diamond
    For i As Integer = 1 To n
        Console.Write(New String(" "c, n - i))
        Console.WriteLine(New String("*"c, 2 * i - 1))
    Next
    For i As Integer = n - 1 To 1 Step -1
        Console.Write(New String(" "c, n - i))
        Console.WriteLine(New String("*"c, 2 * i - 1))
    Next

    ' Christmas tree (stacked tiers)
    Dim tiers As Integer = 3
    Dim baseWidth As Integer = 4 * tiers + 1
    For tier As Integer = 1 To tiers
        Dim rows As Integer = tier + 2
        For r As Integer = 1 To rows
            Dim stars As Integer = 2 * (r + tier - 1) - 1
            Dim spaces As Integer = (baseWidth - stars) \ 2
            Console.Write(New String(" "c, spaces))
            Console.WriteLine(New String("*"c, stars))
        Next
    Next
    ' Trunk
    For t As Integer = 1 To tiers
        Console.Write(New String(" "c, (baseWidth - 3) \ 2))
        Console.WriteLine(New String("|"c, 3))
    Next
End Sub

Troubleshooting notes: off-by-one errors are the most common bug (check loop ranges). Use Step -1 for the descending half of symmetric shapes to avoid duplicated center rows. For Windows Forms or a forum post, build lines into a StringBuilder and assign once (or use TextBox.AppendText) rather than many Console calls. For classic VB6 replace New String(" "c, k) with Space$(k) or String$(k, "*").

Recommended Answers

All 3 Replies

Why are you unable to copy and paste the code? Simply highlight all of your code, and do Ctrl+C (if on Windows). And then Ctrl+V to paste it in here. We aren't going to write your program from scratch for you unless we see some effort on your part ... some code, algorithm, or even a specific line you're having a problem with.

Or,
Shift+Arrow keys to highlight, Control(CTRL)+Insert to copy
then
Shift+insert to paste.

BTW nice pic Dani.

sorry but i did end up staying up till 2:30 and figured it out. i have no clue why it wouldnt copy and paste. my computer was being weird at the moment. thanks anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.