Advertisement
JohnJuly

Homework33

Feb 23rd, 2024 (edited)
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 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 Homework33
  8. {
  9.     internal class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isWork = true;
  14.             string exitProgram = "exit";
  15.             int positionInputX = 0;
  16.             int positionInputY = 5;
  17.  
  18.             Dictionary<string, string> wordbook = new Dictionary<string, string>();
  19.  
  20.             wordbook.Add("bread", "food");
  21.             wordbook.Add("pistol", "peapon");
  22.             wordbook.Add("pills", "drug");
  23.  
  24.             while (isWork)
  25.             {
  26.                 Console.WriteLine($"Введите слово из списка чтобы узнать его значение.");
  27.  
  28.                 foreach (string word in wordbook.Keys)
  29.                 {
  30.                     Console.WriteLine(word);
  31.                 }
  32.  
  33.                 Console.SetCursorPosition(positionInputX, positionInputY);
  34.  
  35.                 string userInput = Console.ReadLine();
  36.  
  37.                 if (userInput == exitProgram)
  38.                 {
  39.                     isWork = false;
  40.                     Console.WriteLine("Вы вышли из программы!");
  41.                 }
  42.                 else if (wordbook.ContainsKey(userInput))
  43.                 {
  44.                     Console.WriteLine($"Значение введенного слова : {wordbook[userInput]}");
  45.                 }
  46.                 else
  47.                 {
  48.                     Console.WriteLine("Такого слова нет в словаре");
  49.                 }
  50.  
  51.                 Console.ReadKey();
  52.                 Console.Clear();
  53.             }
  54.         }
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement