Advertisement
MaoChessy

Task 26

Oct 30th, 2020
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2.  
  3. namespace C_sharp_Light
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             bool isOpen = true;
  10.             List<int> forSum = new List<int>();
  11.  
  12.             while (isOpen)
  13.             {
  14.                 int number;
  15.                 Console.WriteLine("Введите:\n*Число \n*Sum - сложить все числа \n*exit - Выход из программы \n\n");
  16.                 string input = Console.ReadLine();
  17.  
  18.                 if(int.TryParse(input,out number))
  19.                 {
  20.                     forSum.Add(number);
  21.                     Console.WriteLine("Число добавлено.");
  22.                     Console.ReadKey();
  23.                     Console.Clear();
  24.                 }
  25.                 else
  26.                 {
  27.                     switch (input)
  28.                     {
  29.                         case "Sum":
  30.                             int res=0;
  31.                             for (int i = 0; i < forSum.Count; i++)
  32.                             {
  33.                                 res += forSum[i];
  34.                                 if (i != forSum.Count - 1)
  35.                                     Console.Write($"{forSum[i]}+");
  36.                                 else
  37.                                     Console.Write($"{forSum[i]}={res}");
  38.                             }
  39.                             break;
  40.                         case "exit":
  41.                             isOpen = false;
  42.                             break;
  43.                         default:
  44.                             Console.WriteLine("Неизвестная команда");
  45.                             break;
  46.                     }
  47.                     Console.ReadKey();
  48.                     Console.Clear();
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement