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;
- string exit = "exit";
- string sum = "sum";
- while (isWorking)
- {
- Console.WriteLine("Введенные числа: " + string.Join(", ", numbers));
- Console.Write($"Введите число или команду {sum}/{exit}:");
- string input = Console.ReadLine();
- if (input == exit)
- {
- Console.WriteLine("Выход из программы.");
- isWorking = false;
- }
- else if (input == sum)
- {
- double bank = 0;
- foreach (double number in numbers)
- {
- bank += number;
- }
- Console.WriteLine($"Сумма введенных чисел: {bank}");
- }
- 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