Advertisement
Dr_Max_Experience

Task 21

Nov 23rd, 2021 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2.  
  3. namespace HomeWorks
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int barMaxPercent = 100;
  10.             int barPercent;
  11.             string userInput;
  12.             char barSymbol;
  13.             int barLength = 10;
  14.             bool isOpen = true;
  15.  
  16.             while (isOpen)
  17.             {
  18.                 Console.Write("Введите процент заполненности bar: ");
  19.                 userInput = Console.ReadLine();
  20.  
  21.                 if (userInput == "exit")
  22.                 {
  23.                     isOpen = false;
  24.                 }
  25.  
  26.                 barPercent = Convert.ToInt32(userInput);
  27.  
  28.                 if (barPercent > barMaxPercent)
  29.                 {
  30.                     barPercent = barMaxPercent;
  31.                 }
  32.                 else if (barPercent < 0)
  33.                 {
  34.                     barPercent = 0;
  35.                 }
  36.  
  37.                 Console.Write("Введите символ, которым будет заполнен bar: ");
  38.                 barSymbol = Convert.ToChar(Console.ReadLine());
  39.  
  40.                 DrawBar(barPercent, barSymbol, barLength, barMaxPercent);
  41.             }
  42.         }
  43.  
  44.         static void DrawBar(int barPercent, char barSymbol, int barLength, int barMaxPercent)
  45.         {
  46.             Console.Clear();
  47.             Console.Write("[");
  48.             int barOnePoint = barMaxPercent / barLength;
  49.  
  50.             if (barPercent > 0 && barPercent < barOnePoint)
  51.             {
  52.                 Console.Write(barSymbol);
  53.             }
  54.  
  55.             for (int i = 1; i < barLength; i++)
  56.             {
  57.                 if (i <= barPercent / barOnePoint)
  58.                 {
  59.                     Console.Write(barSymbol);
  60.                 }
  61.                 else
  62.                 {
  63.                     Console.Write("_");
  64.                 }
  65.             }
  66.  
  67.             Console.WriteLine($"] {barPercent}%");
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement