Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [StartCode]
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- /*
- * Создать программу, которая принимает от пользователя слово и выводит его значение. Если такого слова нет, то следует вывести соответствующее сообщение.
- */
- namespace ConsoleApp4
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Dictionary<int,string> shelf = new Dictionary<int,string>();
- shelf.Add(1, "Пушкин");
- shelf.Add(2, "Толстой");
- shelf.Add(3, "Лермонтов");
- shelf.Add(4, "Гоголь");
- shelf.Add(5, "Донцова");
- Console.Write("Укажите цифру :");
- int userInput = int.Parse(Console.ReadLine());
- DisplayAuthor(shelf,userInput);
- }
- static void DisplayAuthor(Dictionary <int,string> shelf,int userInput)
- {
- int notFound = 0;
- for (int i = 0; i < shelf.Count+1; i++)
- {
- if (i== userInput)
- {
- Console.WriteLine(shelf[i]);
- notFound++;
- }
- }
- if(notFound == 0)
- {
- Console.WriteLine("Таких писак нету.");
- }
- }
- }
- }
- [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment