Created
May 20, 2025 20:06
-
-
Save ZastiX07/d4010107bd7ce4cea03f811494fdf8f7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 _My_New_Home_Work_ | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string SumCommand = "sum"; | |
const string ExitCommand = "exit"; | |
bool isWork = true; | |
List<int> numbers = new List<int>(); | |
int sum = 0; | |
while (isWork) | |
{ | |
ShowNumbers(numbers); | |
Console.WriteLine($"\nВведите числа либо команду {SumCommand}, либо {ExitCommand} для выхода: "); | |
string userInput = Console.ReadLine(); | |
switch (userInput) | |
{ | |
case SumCommand: | |
ShowSumNumbers(sum); | |
break; | |
case ExitCommand: | |
isWork = false; | |
break; | |
default: | |
sum += AddNumberArray(numbers, userInput); | |
break; | |
} | |
Console.Clear(); | |
} | |
} | |
static void ShowSumNumbers(int sum) | |
{ | |
Console.WriteLine($"Сумма ваших чисел: {sum}"); | |
Console.WriteLine("Нажмите любую клавишу чтобы продолжить..."); | |
Console.ReadKey(); | |
Console.Clear(); | |
} | |
static void ShowNumbers(List<int> numbers) | |
{ | |
for (int i = 0; i < numbers.Count; i++) | |
Console.Write(numbers[i] + "|"); | |
} | |
static int AddNumberArray(List<int> numbers, string userInput) | |
{ | |
int tempNumber = 0; | |
int.TryParse(userInput, out tempNumber); | |
if (tempNumber != 0) | |
numbers.Add(tempNumber); | |
return tempNumber; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment