Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace CSLight
- {
- public class Program
- {
- static void Main(string[] args)
- {
- List<double> numbers = new List<double>();
- bool isWorking = true;
- while (isWorking)
- {
- Console.WriteLine("Введенные числа: " + string.Join(", ", numbers));
- Console.Write("Введите число или команду (sum/exit): ");
- string input = Console.ReadLine();
- if (input == "exit")
- {
- Console.WriteLine("Выход из программы.");
- isWorking = false;
- break;
- }
- else if (input == "sum")
- {
- double sum = 0;
- foreach (double num in numbers)
- {
- sum += num;
- }
- Console.WriteLine($"Сумма введенных чисел: {sum}");
- }
- else
- {
- if (double.TryParse(input, out double number))
- {
- numbers.Add(number);
- Console.WriteLine($"Число {number} добавлено.");
- }
- else
- {
- Console.WriteLine("Некорректный ввод. Пожалуйста, введите число или команду (sum/exit).");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement