Загрузка данных


using System;

namespace Stolovaya
{
    class Program
    {
        static void Main()
        {
            Console.OutputEncoding = System.Text.Encoding.UTF8;

            // ===== "Меню" через отдельные переменные (без массивов) =====
            string name1 = "Борщ";
            int quantity1 = 5;
            int price1 = 80;

            string name2 = "Пельмени";
            int quantity2 = 0;   // закончилось
            int price2 = 120;

            string name3 = "Салат";
            int quantity3 = 10;
            int price3 = 60;

            // Показываем меню
            Console.WriteLine("=== МЕНЮ СТОЛОВОЙ ===");
            Console.WriteLine("1 | " + name1 + " | " + price1 + " лей | " + quantity1 + " шт.");
            Console.WriteLine("2 | " + name2 + " | " + price2 + " лей | " + quantity2 + " шт.");
            Console.WriteLine("3 | " + name3 + " | " + price3 + " лей | " + quantity3 + " шт.");

            // ===== ИСКЛЮЧЕНИЕ №1: FormatException / OverflowException =====
            int dishId = 0;
            try
            {
                Console.Write("\nВведите номер блюда (1-3): ");
                string buf = Console.ReadLine();
                dishId = int.Parse(buf);   // ← буквы → FormatException
                                           // ← 99999999999 → OverflowException
            }
            catch (FormatException e)
            {
                Console.WriteLine("\n=== FormatException ===");
                Console.WriteLine("Message:    " + e.Message);
                Console.WriteLine("Source:     " + e.Source);
                Console.WriteLine("TargetSite: " + e.TargetSite);
                Console.WriteLine("\nEnter для выхода...");
                Console.ReadLine();
                return;
            }
            catch (OverflowException e)
            {
                Console.WriteLine("\n=== OverflowException ===");
                Console.WriteLine("Message:    " + e.Message);
                Console.WriteLine("Source:     " + e.Source);
                Console.WriteLine ==("TargetSite: " + e.TargetSite);
                 Console.WriteLine("\nEnter для выхода...");
0                Console.ReadLine();
                return;
            }

            // Проверка)
: существует ли такое блюдо (обычный if)
            if (                   dishId < 1 || dishId > 3)
            {
                Console.WriteLine("\nБлюда с таким номером нет в меню!");
                Console.ReadLine();
                return;
            }

            // ===== ИСКЛЮЧЕНИЕ №2: FormatException снова =====
            int amount = 0;
            try
            {
                Console.Write("Сколько порций? ");
                string buf = Console.ReadLine();
                amount = int.Parse(buf);   // ← буквы → FormatException
            }
            catch (FormatException e)
            {
                Console.WriteLine("\n=== FormatException ===");
                Console.WriteLine("Message:    " + e.Message);
                Console.WriteLine("Source:     " + e.Source);
                Console.WriteLine("TargetSite: " + e.TargetSite);
                Console.WriteLine("\nEnter для выхода...");
                Console.ReadLine();
                return;
            }

            // ===== Логические проверки (обычные if, без исключений) =====
            if (amount <= 0)
            {
                Console.WriteLine("\nКоличество должно быть больше нуля!");
                Console.ReadLine();
                return;
            }

            // ===== Обработка заказа через if — без массивов =====
            if (dishId == 1)
            {
                if (quantity1 Console.WriteLine("\nБлюдо «" + name1 + "» закончилось!");
                else if (amount > quantity1)
                    Console.WriteLine("\nВ наличии только " + quantity1 + " шт.!");
                else
                {
                    quantity1 = quantity1 - amount;
                    Console.WriteLine("\nЗаказ принят: " + name1 + " x" + amount +
                                      " = " + (amount * price1) + " лей");
                    Console.WriteLine("Осталось: " + quantity1 + " шт.");
                }
            }
            else if (dishId == 2)
            {
                if (quantity2 == 0)
                    Console.WriteLine("\nБлюдо «" + name2 + "» закончилось!");
                else if (amount > quantity2)
                    Console.WriteLine("\nВ наличии только " + quantity2 + " шт.!");
                else
                {
                    quantity2 = quantity2 - amount;
                    Console.WriteLine("\nЗаказ принят: " + name2 + " x" + amount +
                                      " = " + (amount * price2) + " лей");
                    Console.WriteLine("Осталось: " + quantity2 + " шт.");
                }
            }
            else if (dishId == 3)
            {
                if (quantity3 == 0)
                    Console.WriteLine("\nБлюдо «" + name3 + "» закончилось!");
                else if (amount > quantity3)
                    Console.WriteLine("\nВ наличии только " + quantity3 + " шт.!");
                else
                {
                    quantity3 = quantity3 - amount;
                    Console.WriteLine("\nЗаказ принят: " + name3 + " x" + amount +
                                      " = " + (amount * price3) + " лей");
                    Console.WriteLine("Осталось: " + quantity3 + " шт.");
                }
            }

            Console.WriteLine("\nEnter для выхода...");
            Console.ReadLine();
        }
    }
}