Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace CSLight
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- const string CommandSum = "Sum";
- const string CommandExit = "Exit";
- List<int> numbers = new List<int>();
- bool isInProgress = true;
- while (isInProgress)
- {
- if (numbers.Count > 0)
- {
- Console.WriteLine("Числа в массиве");
- for (int i = 0; i < numbers.Count; i++)
- {
- Console.Write(numbers[i] + " ");
- }
- }
- Console.WriteLine();
- Console.WriteLine("Введите команду или число");
- string userInput = Console.ReadLine();
- switch (userInput)
- {
- case CommandSum:
- int sum = 0;
- foreach (int number in numbers)
- {
- sum += number;
- }
- Console.WriteLine($"Сумма всех чисел = {sum}");
- break;
- case CommandExit:
- isInProgress = false;
- break;
- default:
- if (int.TryParse(userInput, out int parsedNumber))
- {
- numbers.Add(parsedNumber);
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine("Неизвестная команда");
- }
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement