Hello,

I have a problem with coding circumscribed rectangle in C# console application.

Whith that code i get just filled rectangle which is not correct fot my task:

//Entering dimensions of the rectangle
            Console.Write("Enter the height of the rectangle: ");
            int Height = int.Parse(Console.ReadLine());
            Console.Write("Enter the width of the rectangle: ");
            int Width = int.Parse(Console.ReadLine());

            Console.WriteLine("--------------------------------------");

            //Display lines
            for (int i = 1; i <= Height; i++)
            {
                //Display columns
                for (int j = 1; j <= Width; j++)
                {
                    Console.Write("*");
                }
                //Go to the next line
                Console.WriteLine();
            }
            Console.ReadLine();

I need to get the circumscribed rectangle which seems something like that:

http://img232.imageshack.us/img232/1260/rectangle.jpg

If anyone can help me with that task to work correctly,
I'm gonna to support this website.

Any help is welcome,

Regards,
bisiii

Recommended Answers

All 4 Replies

Please use code tags if you post code.
Throwing in some if-statements may help:

Console.WriteLine("--------------------------------------");

            //Display lines
            for (int i = 1; i <= Height; i++)
            {
                //Display columns
                for (int j = 1; j <= Width; j++)
                {
                    if (i == 1 || i == Height)
                        Console.Write("*");
                    else
                        if (j == 1 || j == Width)
                            Console.Write("*");
                        else
                            Console.Write(" ");
                }
                //Go to the next line
                Console.WriteLine();
            }
            Console.ReadLine();

It works :)

Thank you so much ddanbe.

Let's support this website ;)

Well just mark this as solved.
Happy computing! :)

Well just mark this as solved.
Happy computing! :)

Done.

Thanks. Wish to you the same.

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.