Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- const string sumCommand = "sum";
- const string exitCommand = "exit";
- List<int> arrayNumbers = new List<int>();
- string userInput;
- bool isRunning = true;
- while (isRunning == true)
- {
- Console.Write("Введите команду: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case sumCommand:
- Summary(arrayNumbers);
- break;
- case exitCommand:
- isRunning = false;
- break;
- default:
- AddNumber(arrayNumbers,userInput);
- break;
- }
- }
- }
- private static void AddNumber(List<int> arrayNumbers, string userInput)
- {
- if (int.TryParse(userInput, out int userNumber))
- {
- arrayNumbers.Add(userNumber);
- Console.WriteLine("Введено число " + userNumber);
- }
- else
- {
- Console.WriteLine("Неверный ввод команды!");
- }
- }
- private static void Summary(List<int> arrayNumbers)
- {
- int sum = 0;
- foreach (var number in arrayNumbers)
- sum += number;
- Console.WriteLine(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement