2

I'm not being able to display the output window, can anybody tell me what I am missing here? I'm trying to display the # symbol in pyramid form.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace variable
{
    class Program
    {
        static void Main()
        {
            for (int row = 0; row < 6; row++)
            {
                // Counting backwards here!
                for (int spaces = 6 - row; spaces > 0; spaces--)
                {
                    Console.Write(" ");
                }

                for (int column = 0; column < (2 * row + 1); column++)
                {
                    Console.Write("#");
                }
                Console.WriteLine();
            }
            Console.Read();
        }
    }
}
Alexander
  • 2,320
  • 2
  • 25
  • 33

2 Answers2

1

I'm assuming you have configured the project as a windows forms project.

So you don't have any console.

You have three options:

  1. Set the project type to Console Application. This is most likely not feasable as it will require too many changes for your application.
  2. Attach a console using P/Invoke. See Show Console in Windows Application? . The advantage over option 3. is that you can display this console in release as well.
  3. Use Trace.Write / Debug.Write to write to Visual Studio's output window.
Community
  • 1
  • 1
wollnyst
  • 1,683
  • 1
  • 17
  • 20
-1

Remove one } after Console.Read();

Looks like a compile error and its working other than that. You will get the output in the console

using System.IO;
using System;
class Program
{
    static void Main()
    {
        // Read in every line in the file.
        for (int row = 0; row < 6; row++)
        {
                // Counting backwards here!
            for (int spaces = 6 - row; spaces > 0; spaces--)
            {
                Console.Write(" ");
            }

            for (int column = 0; column < (2 * row + 1); column++)
            {
                Console.Write("#");

            }

             Console.WriteLine();
         }
         Console.Read();
    }
}

Output:

      #
     ###
    #####
   #######
  #########
 ###########
Dexters
  • 2,419
  • 6
  • 37
  • 57