Advertisement
TravaMan

Basic_Task17

Dec 15th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Basic_Task17
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             DrawBar(45);
  10.             DrawBar(20, 2);
  11.             DrawBar(100, 4);
  12.         }
  13.  
  14.         public static void DrawBar(int percent, int position = 0)
  15.         {
  16.             string bar = "[";
  17.  
  18.             if (percent > 100)
  19.             {
  20.                 percent = 100;
  21.             } else if (percent < 0)
  22.             {
  23.                 percent = 0;
  24.             }
  25.  
  26.             for (int i = 1; i <= 10; i++)
  27.             {
  28.                 if (percent / 10 >= i)
  29.                 {
  30.                     bar += "#";
  31.                 } else
  32.                 {
  33.                     bar += "_";
  34.                 }
  35.             }
  36.             bar += "]";
  37.  
  38.             Console.SetCursorPosition(0, position);
  39.             Console.WriteLine(bar);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement