Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Test
- {
- class Program
- {
- static void Main(string[] args)
- {
- int fillPercent = 100;
- int barValue = 10;
- DrawBar(barValue, fillPercent);
- do
- {
- Console.SetCursorPosition(0, 3);
- Console.Write("Введите процент шкалы: ");
- fillPercent = Convert.ToInt32(Console.ReadLine());
- Console.Clear();
- DrawBar(barValue, fillPercent, ConsoleColor.Red);
- Console.WriteLine("Нажмите 'e' чтобы выйти из программы; Enter - для продолжения");
- } while (Console.ReadLine() != "e");
- }
- static void DrawBar(int barValue, int fillPercent, ConsoleColor color = ConsoleColor.Red)
- {
- ConsoleColor defaultColor = Console.BackgroundColor;
- string bar = "";
- double value = (barValue * fillPercent) / 100;
- for (int i = 0; i < Convert.ToInt32(value); i++)
- {
- bar += '#';
- }
- Console.SetCursorPosition(0, 0);
- Console.Write("[");
- Console.BackgroundColor = color;
- Console.Write(bar);
- Console.BackgroundColor = defaultColor;
- bar = "";
- for (int i = Convert.ToInt32(value); i < barValue; i++)
- {
- bar += '_';
- }
- Console.Write($"{bar}]");
- Console.SetCursorPosition(0, 6);
- }
- }
- }
Add Comment
Please, Sign In to add comment