Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- class IsoscelesTriangle
- {
- static void Main()
- {
- Console.OutputEncoding = Encoding.UTF8;
- char copyrightsign = '\u00A9';
- Console.WriteLine("This program will draw an Isosceles Triangle with height up to 50 rows.");
- Console.Write("Please enter the desired triangle's height:");
- string userinput = Console.ReadLine();
- int leftspace;
- int innerspace = 1;
- char space = ' ';
- byte height;
- while (!byte.TryParse(userinput, out height) || height > 50)
- {
- Console.WriteLine("Invalid input data. Please enter a positive integer up to number 50:");
- userinput = Console.ReadLine();
- }
- for (byte row = 1; row <= height; row++)
- {
- leftspace = height - row;
- Console.Write(new string(space, leftspace) + copyrightsign); //This part gets drawn every time
- if (row > 1 && row < height)
- {
- Console.Write(new string(space, innerspace) + copyrightsign);
- innerspace += 2;
- }
- if (row == height)
- {
- for (int i = height; i > 1; i--)
- {
- Console.Write(new string(space, 1) + copyrightsign); //This is for the last row
- }
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement