GPbl3YH

CSLight #26

Feb 3rd, 2021 (edited)
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CSLight
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> array = new List<int>();
  14.             string userInput;
  15.             int digit;
  16.             int sum;
  17.             bool isRunning = true;
  18.  
  19.             while (isRunning)
  20.             {
  21.                 userInput = Console.ReadLine().ToLower();
  22.  
  23.                 if (int.TryParse(userInput, out digit))
  24.                 {
  25.                     array.Add(digit);
  26.                     continue;
  27.                 }
  28.  
  29.                 if (userInput == "sum")
  30.                 {
  31.                     sum = 0;
  32.                     for (int i = 0; i < array.Count; i++)
  33.                     {
  34.                         sum += array[i];
  35.                     }
  36.                     Console.WriteLine($"Сумма = {sum}");
  37.                     continue;
  38.                 }
  39.  
  40.                 if (userInput == "exit")
  41.                 {
  42.                     isRunning = false;
  43.                     continue;
  44.                 }
  45.  
  46.                 Console.WriteLine("Повторите ввод:");
  47.             }
  48.  
  49.             Console.WriteLine("Конец");
  50.             Console.ReadKey();
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment