Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> userList = new List<int>();
- while (true)
- {
- Console.Write("Ввидите число или слово:");
- string userInput = Console.ReadLine();
- if (userInput == "exit")
- {
- break;
- }
- else if (userInput == "sum")
- {
- int sum = 0;
- for (int i = 0; i < userList.Count; i++)
- {
- sum += userList[i];
- }
- Console.WriteLine("Сумма введённых чисел равна " + sum);
- }
- else
- {
- bool result = int.TryParse(userInput, out int number);
- if (result == true)
- {
- userList.Add(number);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement