hnyrenhjm5678

Untitled

Jan 29th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.16 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         string[] productNames = new string[100];
  8.         int[] productQuantities = new int[100];
  9.         int productCount = 0;
  10.  
  11.         while (true)
  12.         {
  13.             Console.WriteLine("1. Покажи всички продукти");
  14.             Console.WriteLine("2. Създай нов продукт");
  15.             Console.WriteLine("3. Редактирай продукт");
  16.             Console.WriteLine("4. Изтрий продукт");
  17.             Console.WriteLine("5. Изход от програмата");
  18.             Console.Write("Изберете опция: ");
  19.             string choice = Console.ReadLine();
  20.  
  21.             if (choice == "1")
  22.             {
  23.                 for (int i = 0; i < productCount; i++)
  24.                 {
  25.                     Console.WriteLine($"{i + 1}. {productNames[i]} - {productQuantities[i]} бр.");
  26.                 }
  27.             }
  28.             else if (choice == "2")
  29.             {
  30.                 Console.Write("Въведете име на продукта: ");
  31.                 string name = Console.ReadLine();
  32.                 Console.Write("Въведете количество: ");
  33.                 int quantity = int.Parse(Console.ReadLine());
  34.                 productNames[productCount] = name;
  35.                 productQuantities[productCount] = quantity;
  36.                 productCount++;
  37.             }
  38.             else if (choice == "3")
  39.             {
  40.                 Console.Write("Въведете номер на продукта за редакция: ");
  41.                 int index = int.Parse(Console.ReadLine()) - 1;
  42.                 if (index >= 0 && index < productCount)
  43.                 {
  44.                     Console.Write("Ново име на продукта: ");
  45.                     productNames[index] = Console.ReadLine();
  46.                     Console.Write("Ново количество: ");
  47.                     productQuantities[index] = int.Parse(Console.ReadLine());
  48.                 }
  49.                 else
  50.                 {
  51.                     Console.WriteLine("Невалиден номер.");
  52.                 }
  53.             }
  54.             else if (choice == "4")
  55.             {
  56.                 Console.Write("Въведете номер на продукта за изтриване: ");
  57.                 int index = int.Parse(Console.ReadLine()) - 1;
  58.                 if (index >= 0 && index < productCount)
  59.                 {
  60.                     for (int i = index; i < productCount - 1; i++)
  61.                     {
  62.                         productNames[i] = productNames[i + 1];
  63.                         productQuantities[i] = productQuantities[i + 1];
  64.                     }
  65.                     productCount--;
  66.                 }
  67.                 else
  68.                 {
  69.                     Console.WriteLine("Невалиден номер.");
  70.                 }
  71.             }
  72.             else if (choice == "5")
  73.             {
  74.                 break;
  75.             }
  76.             else
  77.             {
  78.                 Console.WriteLine("Невалиден избор. Опитайте отново.");
  79.             }
  80.         }
  81.     }
  82. }
  83.  
Add Comment
Please, Sign In to add comment