OldBeliver

Array_04

Mar 16th, 2021 (edited)
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CSharpArray_04
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] memory = new int[0];
  14.             bool isExit = false;
  15.             string userInput;
  16.  
  17.             while (!isExit)
  18.             {
  19.                 Console.Write($"Введите команду или число для запоминания: ");
  20.                 userInput = Console.ReadLine();
  21.  
  22.                 switch (userInput)
  23.                 {
  24.                     case "exit":
  25.                     case "учше":
  26.                         isExit = true;
  27.                         break;
  28.                     case "sum":
  29.                     case "ыгь":
  30.                         Console.WriteLine($"подождите, идет суммирование ...");
  31.                         int totalSum = 0;
  32.                         for (int i = 0; i < memory.Length; i++)
  33.                         {
  34.                             totalSum += memory[i];
  35.                         }
  36.                         Console.WriteLine($"Общая сумма чисел {totalSum}");
  37.                         break;
  38.                     default:
  39.                         int checkEverySymbol;
  40.                         bool isWholeNumber = true;
  41.  
  42.                         for (int i = 0; i < userInput.Length; i++)
  43.                         {
  44.                             checkEverySymbol = Convert.ToInt32(userInput[i]);
  45.                            
  46.                             if (checkEverySymbol == 45 && i != 0)
  47.                             {
  48.                                 Console.WriteLine($"знак минус поставлен не в начале");
  49.                                 isWholeNumber = false;                                
  50.                             }
  51.                             else if (checkEverySymbol == 45 && userInput.Length == 1)
  52.                             {
  53.                                 Console.WriteLine($"введен только знак минус");
  54.                                 isWholeNumber = false;                                
  55.                             }
  56.  
  57.                             if (checkEverySymbol >= 47 && checkEverySymbol <= 57)
  58.                             {
  59.                                 isWholeNumber = true;
  60.                             }
  61.                             else
  62.                             {
  63.                                 isWholeNumber = false;
  64.                             }
  65.                         }
  66.                        
  67.                         if (isWholeNumber)
  68.                         {                            
  69.                             int[] tempMemory = new int[memory.Length + 1];
  70.                             for (int j = 0; j < memory.Length; j++)
  71.                             {
  72.                                 tempMemory[j] = memory[j];
  73.                             }
  74.                             tempMemory[tempMemory.Length - 1] = Convert.ToInt32(userInput);
  75.                             memory = tempMemory;                            
  76.                         }
  77.                         else
  78.                         {
  79.                             Console.WriteLine("данные не соответствуют");
  80.                         }
  81.                         break;
  82.                 }            
  83.             }
  84.  
  85.         }
  86.     }
  87. }
  88.  
Add Comment
Please, Sign In to add comment