Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace C_Sharp_Junior
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<int> numberList = new List<int>();
- bool isExit = true;
- bool result;
- while (isExit)
- {
- Console.Write("Ввидите число или слово:");
- string userInput = Console.ReadLine();
- if (userInput == "exit")
- {
- isExit = false;
- }
- else if (userInput == "sum")
- {
- int sum = 0;
- for (int i = 0; i < numberList.Count; i++)
- {
- sum += numberList[i];
- }
- Console.WriteLine("Сумма введённых чисел равна: " + sum);
- }
- else
- {
- result = int.TryParse(userInput, out int number);
- if (result == true)
- {
- numberList.Add(number);
- }
- else
- {
- Console.WriteLine("Преобразование не удалось. Повторите попытку.");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement