Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Collections;
- using System.Collections.Generic;
- namespace HomeWorks
- {
- class Program
- {
- static void Main(string[] args)
- {
- bool isOpen = true;
- string userInput;
- bool isNumber;
- List<int> values = new List<int>();
- while (isOpen)
- {
- Console.Clear();
- Console.Write("Введите комманду sum или число: ");
- userInput = Console.ReadLine();
- if (userInput == "exit")
- {
- isOpen = false;
- }
- else if (userInput == "sum")
- {
- int sum = 0;
- foreach (var value in values)
- {
- sum += value;
- }
- Console.WriteLine($"Сумма введённых чисел = {sum}");
- values.Clear();
- Console.ReadKey();
- }
- else
- {
- CheckCorrectnessInput(userInput, out isNumber);
- if (isNumber)
- {
- values.Add(Convert.ToInt32(userInput));
- }
- }
- }
- }
- static void CheckCorrectnessInput(string userInput, out bool isNumber)
- {
- isNumber = int.TryParse(userInput, out int intValue);
- if (isNumber == false)
- {
- Console.Write("Некорректный ввод!");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment