Advertisement
VKNikov

Drawing Isosceles Triangle

Mar 19th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. class IsoscelesTriangle
  5. {
  6.     static void Main()
  7.     {
  8.         Console.OutputEncoding = Encoding.UTF8;
  9.         char copyrightsign = '\u00A9';
  10.         Console.WriteLine("This program will draw an Isosceles Triangle with height up to 50 rows.");
  11.         Console.Write("Please enter the desired triangle's height:");
  12.         string userinput = Console.ReadLine();
  13.         int leftspace;
  14.         int innerspace = 1;
  15.         char space = ' ';
  16.         byte height;
  17.         while (!byte.TryParse(userinput, out height) || height > 50)
  18.         {
  19.             Console.WriteLine("Invalid input data. Please enter a positive integer up to number 50:");
  20.             userinput = Console.ReadLine();
  21.         }
  22.         for (byte row = 1; row <= height; row++)
  23.         {
  24.             leftspace = height - row;
  25.             Console.Write(new string(space, leftspace) + copyrightsign); //This part gets drawn every time
  26.             if (row > 1 && row < height)
  27.             {
  28.                 Console.Write(new string(space, innerspace) + copyrightsign);
  29.                 innerspace += 2;
  30.             }
  31.             if (row == height)
  32.             {
  33.                 for (int i = height; i > 1; i--)
  34.                 {
  35.                     Console.Write(new string(space, 1) + copyrightsign); //This is for the last row
  36.                 }
  37.             }
  38.             Console.WriteLine();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement