Skip to content

Instantly share code, notes, and snippets.

@Soulstorm50
Last active November 26, 2016 22:24
Show Gist options
  • Save Soulstorm50/16ecfea06a22a35d1f1205471b3e9768 to your computer and use it in GitHub Desktop.
Save Soulstorm50/16ecfea06a22a35d1f1205471b3e9768 to your computer and use it in GitHub Desktop.
C# Лесенка
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
StairBuilder xxx = new StairBuilder();
xxx.Start();
}
}
class StairBuilder
{
private int spaceCount = 0;
public void Start()
{
Console.WriteLine("Enter the number of stairs: ");
string userText = Console.ReadLine();
bool onlyDigits = true;
foreach (var item in userText)
{
if (!Char.IsDigit(item))
{
onlyDigits = false;
Console.WriteLine("\nWrong symbol: " + item + ". Only digits are allowed.\n");
break;
}
}
if (onlyDigits)
{
int stairCount = Convert.ToInt32(userText);
for (int i = 0; i < stairCount; i++)
OutPutStair();
OutPutWhiteSpaces();
Console.WriteLine("***\n");
}
}
private void OutPutWhiteSpaces()
{
for (int i = 0; i < spaceCount; i++)
Console.Write(" ");
}
private void OutPutStair()
{
OutPutWhiteSpaces();
Console.WriteLine("***");
OutPutWhiteSpaces();
Console.WriteLine(" *");
spaceCount += 2;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment