Skip to content

Instantly share code, notes, and snippets.

@trayforyou
Created April 27, 2024 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trayforyou/9c29d8aa745c5b852d72606cc8942eba to your computer and use it in GitHub Desktop.
Save trayforyou/9c29d8aa745c5b852d72606cc8942eba to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
namespace Collections2
{
internal class Program
{
static void Main(string[] args)
{
bool isOpen = true;
string userInput;
int userInputNumber;
List<int> numbers = new List<int>();
while (isOpen)
{
Console.Clear();
Console.Write("Ввеите число или команду: ");
userInput = Console.ReadLine();
if (int.TryParse(userInput, out userInputNumber))
{
numbers.Add(userInputNumber);
}
else if (userInput == "sum")
{
int sum = 0;
foreach (int number in numbers)
{
sum += number;
}
Console.WriteLine($"Сумма всех чисел равна: {sum}.");
Console.ReadKey();
}
else if (userInput == "exit")
{
isOpen = false;
}
else
{
Console.WriteLine("Команда не распознана, попробуйте еще раз");
Console.ReadKey();
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment