the output should be:
Triangle Drawer

Enter the size of the triangle: 0
The size is out of range.
Enter the size of the triangle: 11
The size is out of range.
Enter the size of the triangle: cats
An invalid value was entered.
Enter the size of the triangle: 10

TTTTTTTTTT
TTTTTTTTT
TTTTTTTT
TTTTTTT
TTTTTT
TTTTT
TTTT
TTT
TT
T

Press any key to exit:

Console.Title = "Triangle Drawer";

            Console.Write("{0, 40}", "Triangle Drawer");

            int iSize = 0;
            bool bError;

            do
            {
                try
                {
                    bError = false;
                    Console.Write("\nEnter the size of the triangle: ");
                    iSize = int.Parse(Console.ReadLine());

                    if ((iSize <= 1) || (iSize >= 11))
                    {
                        Console.Write("\nThe size is out of range.");
                        bError = true;
                    }
                }
                catch (FormatException)
                {
                    Console.Write("\nAn invalid value was entered.");
                    bError = true;
                }
                finally
                {
                    Console.WriteLine("");
                    bError = true;
                }
                for (int iRow = 0; iRow < iSize; iRow++)
                {
                    for (int iColumn = 0; iColumn < iSize; iColumn++)
                        Console.Write("T");
                    Console.WriteLine();
                }
            }
            while (bError);

            Console.WriteLine("Press any key to exit.");
            Console.ReadLine();

mine is showing like this
TTTT
TTTT
TTTT
TTTT
TTTT

Recommended Answers

All 8 Replies

Your second for loop's conditional part should be iColumn <= iSize - iRow .

Line32 should be for (int iRow = iSize; iRow > 0; iRow--) { Line 34 should be for (int iColumn = 0; iColumn < iRow; iColumn++) {

how come if press 1 or 11 for iSize

its showing:
The size is out of range.
"T"

Instead of setting bError = true; , just take out bError entirely and use continue; instead where bError = true; used to be. Replace the while(bError) with while(true) .

i have another question.
just to make sure
am i using double for loop???

No, why would you draw a triangle with base 5.2? You can't draw part of a T. int fits everything between 2 and 10 (and much more) so it's all you need.

im just following what is the instruction said...
can u tell me how to use double for loop?

Yes, you're using 2 for loops, if that's what the instructions mean.

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.