Advertisement
LeRoY_Go

Untitled

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