Vapio

task25

Apr 22nd, 2021
654
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class Program
  5. {
  6.     public static void Main()
  7.     {
  8.         List<int> listNumbers = new List<int>();
  9.        
  10.         long sumNumbers = 0;
  11.        
  12.         int inputNumber;
  13.         string inputString = null;
  14.  
  15.         bool isRun = true;
  16.         bool isNumber = true;
  17.  
  18.         while (isRun)
  19.         {
  20.             inputNumber = InputNumber(ref isNumber, ref inputString);
  21.  
  22.             if (isNumber)
  23.             {
  24.                 sumNumbers += inputNumber;
  25.                 listNumbers.Add(inputNumber);
  26.             }
  27.             else
  28.             {
  29.                 switch (inputString)
  30.                 {
  31.                     case "sum":
  32.                         Console.WriteLine($"The sum of numbers is : {sumNumbers}");
  33.                         break;
  34.                     case "exit":
  35.                         isRun = false;
  36.                         break;
  37.                     default:
  38.                         Console.WriteLine("You write wrong number or command.");
  39.                         break;
  40.                 }
  41.             }
  42.         }
  43.     }
  44.  
  45.     public static int InputNumber(ref bool isNumber, ref string inputString)
  46.     {
  47.         int inputNumber;
  48.        
  49.         Console.WriteLine("Input a number or a command: ");
  50.         inputString = Console.ReadLine();
  51.         isNumber = int.TryParse(inputString, out inputNumber);
  52.        
  53.         return inputNumber;
  54.     }
  55. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×