Askor

Hw20

Jul 11th, 2020 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 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.  
  8. namespace Test
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int fillPercent = 100;
  15.             int barValue = 10;
  16.  
  17.             DrawBar(barValue, fillPercent);
  18.  
  19.             do
  20.             {
  21.                 Console.SetCursorPosition(0, 3);
  22.                 Console.Write("Введите процент шкалы: ");
  23.                 fillPercent = Convert.ToInt32(Console.ReadLine());
  24.  
  25.                 Console.Clear();
  26.                 DrawBar(barValue, fillPercent, ConsoleColor.Red);
  27.  
  28.                 Console.WriteLine("Нажмите 'e' чтобы выйти из программы; Enter - для продолжения");
  29.             } while (Console.ReadLine() != "e");
  30.         }
  31.  
  32.         static void DrawBar(int barValue, int fillPercent, ConsoleColor color = ConsoleColor.Red)
  33.         {
  34.             ConsoleColor defaultColor = Console.BackgroundColor;
  35.             string bar = "";
  36.             double value = (barValue * fillPercent) / 100;
  37.  
  38.             for (int i = 0; i < Convert.ToInt32(value); i++)
  39.             {
  40.                 bar += '#';
  41.             }
  42.  
  43.             Console.SetCursorPosition(0, 0);
  44.             Console.Write("[");
  45.             Console.BackgroundColor = color;
  46.             Console.Write(bar);
  47.             Console.BackgroundColor = defaultColor;
  48.  
  49.             bar = "";
  50.  
  51.             for (int i = Convert.ToInt32(value); i < barValue; i++)
  52.             {
  53.                 bar += '_';
  54.             }
  55.  
  56.             Console.Write($"{bar}]");
  57.             Console.SetCursorPosition(0, 6);
  58.         }
  59.     }
  60. }
Add Comment
Please, Sign In to add comment