Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CSharpArray_04
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] memory = new int[0];
- bool isExit = false;
- string userInput;
- while (!isExit)
- {
- Console.Write($"Введите команду или число для запоминания: ");
- userInput = Console.ReadLine();
- switch (userInput)
- {
- case "exit":
- case "учше":
- isExit = true;
- break;
- case "sum":
- case "ыгь":
- Console.WriteLine($"подождите, идет суммирование ...");
- int totalSum = 0;
- for (int i = 0; i < memory.Length; i++)
- {
- totalSum += memory[i];
- }
- Console.WriteLine($"Общая сумма чисел {totalSum}");
- break;
- default:
- int checkEverySymbol;
- bool isWholeNumber = true;
- for (int i = 0; i < userInput.Length; i++)
- {
- checkEverySymbol = Convert.ToInt32(userInput[i]);
- if (checkEverySymbol == 45 && i != 0)
- {
- Console.WriteLine($"знак минус поставлен не в начале");
- isWholeNumber = false;
- }
- else if (checkEverySymbol == 45 && userInput.Length == 1)
- {
- Console.WriteLine($"введен только знак минус");
- isWholeNumber = false;
- }
- if (checkEverySymbol >= 47 && checkEverySymbol <= 57)
- {
- isWholeNumber = true;
- }
- else
- {
- isWholeNumber = false;
- }
- }
- if (isWholeNumber)
- {
- int[] tempMemory = new int[memory.Length + 1];
- for (int j = 0; j < memory.Length; j++)
- {
- tempMemory[j] = memory[j];
- }
- tempMemory[tempMemory.Length - 1] = Convert.ToInt32(userInput);
- memory = tempMemory;
- }
- else
- {
- Console.WriteLine("данные не соответствуют");
- }
- break;
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment