Advertisement
Rodunskiy

Untitled

Dec 5th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel.Design;
  3. using System.Runtime.InteropServices;
  4.  
  5. namespace CSLight
  6. {
  7.     public class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Console.Write("Введите длинну полоски здоровья:");
  12.             int lengthBar = ReadInt();
  13.  
  14.             Console.Write("Введите процент здоровья:");
  15.             int percent = ReadInt();
  16.  
  17.             Console.Write("Введите символ заполнения:");
  18.             char fillChar = Convert.ToChar(Console.ReadLine());
  19.  
  20.             char emptyChar = '_';
  21.  
  22.             DrawBar(percent, lengthBar, fillChar, emptyChar);
  23.         }
  24.  
  25.         static void DrawBar(int percent, int lengthBar, char fillChar, char emptyChar)
  26.         {          
  27.             int divider = 100;
  28.  
  29.             int filledLength = (percent * lengthBar) / divider;
  30.             int emptyLength = lengthBar - filledLength;
  31.  
  32.             Console.Write('[');
  33.             FillingBar(fillChar, filledLength);
  34.             FillingBar(emptyChar, emptyLength);
  35.             Console.Write(']');
  36.         }
  37.  
  38.         static void FillingBar(char fillingChar, int length)
  39.         {
  40.             Console.Write(new string(fillingChar, length));
  41.         }
  42.  
  43.         static int ReadInt()
  44.         {
  45.             int number = 0;
  46.  
  47.             while (int.TryParse(Console.ReadLine(), out number) == false)
  48.             {
  49.                 Console.WriteLine("Это не число.");
  50.             }
  51.  
  52.             return number;
  53.         }
  54.     }
  55. }
  56.  
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement