Advertisement
Cataykus

Untitled

Apr 2nd, 2020
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace dz1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             DrawBar(30, 5, 30);
  14.  
  15.             Console.ReadKey();
  16.         }
  17.  
  18.         static void DrawBar(int x, int y, int valueInPercents, int maxValue = 100, ConsoleColor valueColor = ConsoleColor.White)
  19.         {
  20.             int valuePerChar = maxValue / 10;
  21.             float percents = Convert.ToSingle(valueInPercents) / 100;
  22.             float charsQuantity = maxValue * percents / valuePerChar;
  23.  
  24.             Console.SetCursorPosition(x, y);
  25.             Console.ForegroundColor = valueColor;
  26.             Console.Write("[");
  27.             for (int i = 0; i < 10; i++, charsQuantity--)
  28.             {
  29.                 if (charsQuantity > 0)
  30.                 {
  31.                     Console.Write("#");
  32.                 }
  33.                 else
  34.                 {
  35.                     Console.Write(" ");
  36.                 }
  37.             }
  38.             Console.Write("]");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement