Last active
February 4, 2025 19:56
-
-
Save PalcevPV/1448705403f65d3603dec1e83f4f2483 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 Dynamic_array_advanced | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string CommandSum = "sum"; | |
const string CommandExit = "exit"; | |
List<int> numbers = new List<int>(); | |
string userInput; | |
bool isWork = true; | |
bool isCorrect; | |
int inputNumber; | |
int numbersSum = 0; | |
while (isWork) | |
{ | |
Console.WriteLine("Выберите команду или введите число"); | |
Console.WriteLine($"{CommandSum} - cумма чисел"); | |
Console.WriteLine($"{CommandExit} - выход"); | |
userInput = Console.ReadLine(); | |
isCorrect = int.TryParse(userInput, out inputNumber); | |
if (isCorrect) | |
{ | |
numbers.Add(inputNumber); | |
} | |
switch (userInput) | |
{ | |
case CommandExit: | |
isWork = false; | |
break; | |
case CommandSum: | |
GetSum(numbersSum, numbers); | |
break; | |
} | |
Console.Clear(); | |
} | |
} | |
static void GetSum(int numbersSum, List<int> numbers) | |
{ | |
numbersSum = 0; | |
for (int i = 0; i < numbers.Count; i++) | |
{ | |
numbersSum += numbers[i]; | |
} | |
Console.WriteLine("\nСумма чисел: " + numbersSum); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment