Created
April 27, 2024 11:53
-
-
Save trayforyou/9c29d8aa745c5b852d72606cc8942eba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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