Advertisement
HEX0x29A

switch&more

Jun 28th, 2019
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. using System;
  2. namespace testconsole
  3. {
  4.     class Program
  5.     {
  6.         private static readonly string[] var1 = { "Горячее", "Суп" };
  7.         private static readonly string[,] var2 = {
  8.             {
  9.                 "Семга запеченная",
  10.                 "Шашлык из свинины"
  11.             },
  12.             {
  13.                 "Суп – лапша домашняя",
  14.                 "Солянка мясная сборная"
  15.             }
  16.         };
  17.         private static readonly string[] var3 = {
  18.             "Клубничный чизкейк",
  19.             "Фруктовый салат",
  20.             "Мороженое"
  21.         };
  22.        
  23.         private static void printArr(string[,] arr, int id, bool numbers = true)
  24.         {
  25.             for (int i = 0; i < 2; ++i) {
  26.                 if (numbers)
  27.                     Console.Write("{0}.", i + 1);
  28.                 Console.WriteLine(arr[id, i]);
  29.             }
  30.         }
  31.        
  32.         private static void printArr(string[] arr, bool numbers = true)
  33.         {
  34.             for (int i = 0; i < arr.Length; ++i) {
  35.                 if (numbers)
  36.                     Console.Write("{0}.", i + 1);
  37.                 Console.WriteLine(arr[i]);
  38.             }
  39.         }
  40.        
  41.         public static void Main(string[] args)
  42.         {              
  43.             Console.WriteLine("Что желаете заказать?");
  44.             printArr(var1);        
  45.             int step1 = Convert.ToInt32(Console.ReadLine()), step2 = 0, step4 = 0;
  46.             switch (step1) {
  47.                 case 1:
  48.                 {
  49.                     Console.WriteLine("Горячее:");
  50.                     printArr(var2, 0);
  51.                     step2 = Convert.ToInt32(Console.ReadLine());
  52.                     break;
  53.                 }
  54.                 case 2:
  55.                 {
  56.                     Console.WriteLine("Супы:");
  57.                     printArr(var2, 1);
  58.                     step2 = Convert.ToInt32(Console.ReadLine());
  59.                     break;
  60.                 }                  
  61.             }
  62.             Console.WriteLine("Желаете что-нибудь на десерт? (да/нет)");
  63.             string step3 = Console.ReadLine();
  64.             switch (step3.Trim().ToLower()) {
  65.                 case "да":
  66.                 {
  67.                     Console.WriteLine("Десерты:");
  68.                     printArr(var3);
  69.                     step4 = Convert.ToInt32(Console.ReadLine());
  70.                     break;
  71.                 }
  72.                 case "нет":
  73.                     break;
  74.             }
  75.             Console.WriteLine("Заказ: {0}: {1}{2}", var1[step1 - 1], var2[step1 - 1, step2 - 1],
  76.                 step3.Trim().ToLower().Equals("да") ? "; Десерт: " + var3[step4 - 1] : "");
  77.             Console.ReadKey(true);
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement