Calculating and Printing the Roof

We can see from the examples that the roof is made of two towers and a middle part. Each tower has a beginning /, middle ^ and an end \.

\ is a special symbol in C# and using only it in the method Console.WriteLine(…), the console will not print it, that's why we show with \\ that we want to print exactly this symbol, without being interpreted as a special symbol (escaping it).

The size of the middle is n / 2, therefore we can write this value in a new variable. It will keep the size of the middle of the tower.

Now we declare a second variable, which will keep the value of the part between the two towers. The middle of the roofs size is 2 * n - 2 * colSize - 4.

In order to print the roof, we will use new string, which takes two parameters (char, int) and connects a symbol n times.

results matching ""

    No results matching ""