Advertisement
Normantas

Untitled

Sep 11th, 2021
1,418
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.53 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 P2.Sav3
  8. {
  9.     static class Calculator
  10.     {
  11.  
  12.         public static void RunCalculator()
  13.         {
  14.             Info();
  15.  
  16.             Console.WriteLine("Įveskite funkciją (Sveikasis Skaičius)");
  17.             int func = int.Parse(Console.ReadLine());
  18.  
  19.             if (func < 1 || func > 4)
  20.             {
  21.                 Console.WriteLine("Klaidinga operacija");
  22.                 return;
  23.             }
  24.  
  25.             Console.WriteLine("Įveskite pirmąjį skaičių");
  26.             double a = double.Parse(Console.ReadLine());
  27.  
  28.             Console.WriteLine("Įveskite antrąjį skaičių");
  29.             double b = double.Parse(Console.ReadLine());
  30.  
  31.             switch (func)
  32.             {
  33.                 case 1:
  34.                     Addition(a, b);
  35.                     break;
  36.  
  37.                 case 2:
  38.                     Subraction(a, b);
  39.                     break;
  40.  
  41.                 case 3:
  42.                     Multiplication(a, b);
  43.                     break;
  44.  
  45.                 case 4:
  46.                     Devision(a, b);
  47.                     break;
  48.  
  49.                 default:
  50.                     Console.WriteLine("Problema Operacijose");
  51.                     break;
  52.             }
  53.  
  54.         }
  55.  
  56.         // Prints out information needed for the calculator
  57.         private static void Info()
  58.         {
  59.             Console.WriteLine("Skaičiuotuvas");
  60.             Console.WriteLine("-----------------------");
  61.             Console.WriteLine("1): sudėtis (+)");
  62.             Console.WriteLine("2): atimtis (-)");
  63.             Console.WriteLine("3): daugyba (*)");
  64.             Console.WriteLine("4): dalyba  (/)");
  65.             Console.WriteLine("-----------------------");
  66.         }
  67.         private static void Addition (double a, double b) => Console.WriteLine($"{a,0:f} + {b,0:f} = {(double)(a + b),0:f}");
  68.         private static void Subraction (double a, double b) => Console.WriteLine($"{a,0:f} - {b,0:f} = {(double)(a - b),0:f}");
  69.         private static void Multiplication (double a, double b) => Console.WriteLine($"{a,0:f} * {b,0:f} = {(double)(a * b),0:f}");
  70.  
  71.         private static void Devision (double a, double b)
  72.         {
  73.             try
  74.             {
  75.                 Console.WriteLine($"{a,0:f} / {b,0:f} = {(double)(a / b),0:f}");
  76.             }
  77.             catch (Exception)
  78.             {
  79.                 Console.WriteLine("Problema su Dalyba");
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement