Created
August 24, 2024 11:02
-
-
Save IvanEnginer/3dcb12c8dfddb5434728613baf115725 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; | |
namespace HW_02 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string commandToExit = "q"; | |
const string commandToReset = "r"; | |
string input; | |
bool isWork = true; | |
int sum = 0; | |
int[] userNumbers = new int[0]; | |
while (isWork) | |
{ | |
Console.WriteLine("Введите целое число или = для получения результата"); | |
input = Console.ReadLine(); | |
if(int.TryParse(input, out int result)) | |
{ | |
sum += result; | |
int[] tempArray = new int[userNumbers.Length + 1]; | |
for (int i = 0; i < userNumbers.Length; i++) | |
tempArray[i] = userNumbers[i]; | |
tempArray[tempArray.Length - 1] = result; | |
userNumbers = tempArray; | |
Console.Clear(); | |
}else if(input == "=") | |
{ | |
Console.Clear (); | |
Console.WriteLine($"Сумма = {sum}"); | |
Console.Write("Числа которые вы ввели: "); | |
foreach(int number in userNumbers) | |
{ | |
Console.Write(number + " "); | |
} | |
Console.WriteLine("\nВведите q для завершения программы или r для перезагрузки"); | |
input = Console.ReadLine(); | |
switch (input) | |
{ | |
case commandToReset: | |
sum = 0; | |
userNumbers = new int[0]; | |
Console.Clear(); | |
break; | |
case commandToExit: | |
isWork = false; | |
break; | |
default: | |
isWork = false; | |
break; | |
} | |
} | |
else | |
{ | |
Console.WriteLine("Ошибка ввода, введите целое число или = для получения результата"); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment