Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isExit = false;
- List<int> numbers = new List<int>();
- while (!isExit)
- {
- string input = Console.ReadLine();
- switch (input)
- {
- case "exit":
- isExit = true;
- break;
- case "sum":
- int sum = 0;
- foreach (var number in numbers)
- {
- sum += number;
- }
- Console.WriteLine("Сумма всех веденных чисел: " + sum);
- break;
- default:
- int isNumber;
- bool success = Int32.TryParse(input, out isNumber);
- if (success)
- {
- numbers.Add(Convert.ToInt32(input));
- }
- else
- {
- Console.WriteLine("Введите число!");
- }
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement