Thread: asterik tree

  1. #16
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Are you a sorcerer?
    ;_;

    I've spent the last ten minutes cleanup honey tea off my keyboard and monitor.

    It was kind of worth it. ^_^;

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  2. #17
    Registered User
    Join Date
    Jan 2010
    Posts
    208
    I think I understand the code now I replaced the space in the output with an A and it help me visual what the code was doing The only thing I haven't done was center it on the screen but I might ask my teacher about when I get a chance here's the code if anyone's interested

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Chapter6Problem14
    {
        class Program
        {
            static void Main()
            {
                int rows = 11;
                int a, b, c, d, e;
              
                for (a = 1; a <= rows / 2 + 1; a++)
                {
                    
                    for (b = 1; b <= rows - a; b++) 
                        Console.Write("{0}", " ");
                    for (c = 1; c <= (2 * a) - 1; c++)
                        Console.Write("{0}", "X");
                    
                    Console.WriteLine();
                }
                
    
                for (e = 1; e <= rows - 2; e++)
                    Console.Write("{0}"," ");
                for (d = 1; d <= rows / 2 - 2; d++)
                    Console.Write("{0}","X");
                
                
                Console.WriteLine();
                Console.ReadKey();
    
    
    
            }
        }
    }

  3. #18
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,787
    Quote Originally Posted by artistunknown View Post
    I replaced the space in the output with an A and it help me visual what the code was doing
    Good idea! Nice to see you didn't give up.

    Some other suggestions when you're having trouble:
    • Close your editor and grab a pen(cil) and paper
    • Work out exactly what you have to do before you start to code
    • Break the problem down into sub-problems (and those sub-problems into further sub-problems where necessary)
    • Take a break


    The final suggestion (take a break) is recommended because you really can get frustrated and possibly angry. This causes your body to release cortisol and epinephrine (and probably other hormones) which engage your fight/flight response... and you can't think properly when you're like that.
    Last edited by Hodor; 03-21-2014 at 04:57 AM.

  4. #19
    Registered User
    Join Date
    Jan 2010
    Posts
    208
    Good Advice!

  5. #20
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    Some notes, if I may:

    - Try to use descriptive variable names. If you just use a list of arbitrary single letters for variable names, it's much easier to lose track of what variable is being used for what.
    - You don't need that many variables. You can re-use variables outside of the scope in which they were defined. For example, you could get away with just "row" and "column", or at least "r" and "c" or even "x" and "y" if it were clear what they represent.
    - Console.Write() does not require a format string.
    Code:
    Console.Write("{0}", "X")
    could simply be rewritten as
    Code:
    Console.Write("X")
    .
    Last edited by itsme86; 03-23-2014 at 12:40 PM.
    If you understand what you're doing, you're not learning anything.

  6. #21
    Registered User
    Join Date
    Jan 2010
    Posts
    208
    Ok I'll keep that in mind I also might try and rewrite it later 2

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rooted Tree (Family tree)
    By ch4 in forum C Programming
    Replies: 4
    Last Post: 10-14-2008, 04:24 PM
  2. Replies: 2
    Last Post: 08-01-2007, 01:08 PM
  3. display tree data in binary tree format
    By xddxogm3 in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2003, 12:47 AM
  4. Replies: 5
    Last Post: 05-23-2003, 01:11 PM
  5. b-tree (not binary tree) implementation help
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 01-02-2002, 03:30 PM