kwest87

Untitled

Dec 2nd, 2022
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.51 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. /*
  9.  * Создать программу, которая принимает от пользователя слово и выводит его значение. Если такого слова нет, то следует вывести соответствующее сообщение.
  10.  */
  11.  
  12. namespace ConsoleApp4
  13. {
  14.     internal class Program
  15.     {
  16.         static void Main(string[] args)
  17.         {
  18.             Dictionary<int,string> shelf = new Dictionary<int,string>();
  19.             shelf.Add(1, "Пушкин");
  20.             shelf.Add(2, "Толстой");
  21.             shelf.Add(3, "Лермонтов");
  22.             shelf.Add(4, "Гоголь");
  23.             shelf.Add(5, "Донцова");
  24.             Console.Write("Укажите цифру :");
  25.             int userInput = int.Parse(Console.ReadLine());
  26.             DisplayAuthor(shelf,userInput);
  27.         }
  28.  
  29.         static void DisplayAuthor(Dictionary <int,string> shelf,int userInput)
  30.         {
  31.             int notFound = 0;
  32.  
  33.             for (int i = 0; i < shelf.Count+1; i++)
  34.             {
  35.                 if (i== userInput)
  36.                 {
  37.                     Console.WriteLine(shelf[i]);
  38.                     notFound++;
  39.                 }
  40.             }
  41.  
  42.             if(notFound == 0)
  43.             {
  44.                 Console.WriteLine("Таких писак нету.");
  45.             }
  46.         }
  47.     }
  48. }
  49. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment