Advertisement
LeRoY_Go

Untitled

Feb 2nd, 2022
1,374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace C_Sharp_Junior
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<int> numberList = new List<int>();
  11.             bool isExit = true;
  12.             bool result;
  13.             while (isExit)
  14.             {
  15.                 Console.Write("Ввидите число или слово:");
  16.                 string userInput = Console.ReadLine();
  17.                 if (userInput == "exit")
  18.                 {
  19.                     isExit = false;
  20.                 }
  21.                 else if (userInput == "sum")
  22.                 {
  23.                     int sum = 0;
  24.                     for (int i = 0; i < numberList.Count; i++)
  25.                     {
  26.                         sum += numberList[i];
  27.                     }
  28.                     Console.WriteLine("Сумма введённых чисел равна: " + sum);
  29.                 }
  30.                 else
  31.                 {
  32.                     result = int.TryParse(userInput, out int number);
  33.                     if (result == true)
  34.                     {
  35.                         numberList.Add(number);
  36.                     }
  37.                     else
  38.                     {
  39.                         Console.WriteLine("Преобразование не удалось. Повторите попытку.");
  40.                     }
  41.                 }
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement