Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Homework3
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool exit = false;
- List<int> numbers = new List<int>();
- while (exit == false)
- {
- Console.Write("Введите число или команду:");
- string userInput = Console.ReadLine();
- if(int.TryParse(userInput, out int result))
- {
- numbers.Add(result);
- }
- else if (userInput == "exit")
- {
- exit = true;
- }
- else if(userInput == "sum")
- {
- int sum = 0;
- foreach (var number in numbers)
- {
- sum += number;
- }
- Console.WriteLine(sum);
- }
- else
- {
- Console.WriteLine("Это не число!");
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment