Advertisement
OwlyOwl

List_sum

Jun 29th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.CompilerServices;
  4. using System.Linq;
  5.  
  6. namespace testing
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<int> numbers = new List<int>();
  13.             string userInput = null;
  14.  
  15.             while (userInput != "exit")
  16.             {
  17.                 Console.WriteLine("Введи число:");
  18.                 int newNumber = Convert.ToInt32(Console.ReadLine());
  19.                 numbers.Add(newNumber);
  20.                 Console.WriteLine("exit - для выхода. \nsum - вывести сумму. \nНажмите enter, чтобы продолжить ввод.");
  21.                 userInput = Convert.ToString(Console.ReadLine());
  22.                 Console.Clear();
  23.                 if (userInput == "sum")
  24.                 {
  25.                     int total = numbers.Sum(x => Convert.ToInt32(x));
  26.                     Console.WriteLine(total + " - Сумма");
  27.                 }
  28.             }
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement