Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace P2.Sav3
- {
- static class Calculator
- {
- public static void RunCalculator()
- {
- Info();
- Console.WriteLine("Įveskite funkciją (Sveikasis Skaičius)");
- int func = int.Parse(Console.ReadLine());
- if (func < 1 || func > 4)
- {
- Console.WriteLine("Klaidinga operacija");
- return;
- }
- Console.WriteLine("Įveskite pirmąjį skaičių");
- double a = double.Parse(Console.ReadLine());
- Console.WriteLine("Įveskite antrąjį skaičių");
- double b = double.Parse(Console.ReadLine());
- switch (func)
- {
- case 1:
- Addition(a, b);
- break;
- case 2:
- Subraction(a, b);
- break;
- case 3:
- Multiplication(a, b);
- break;
- case 4:
- Devision(a, b);
- break;
- default:
- Console.WriteLine("Problema Operacijose");
- break;
- }
- }
- // Prints out information needed for the calculator
- private static void Info()
- {
- Console.WriteLine("Skaičiuotuvas");
- Console.WriteLine("-----------------------");
- Console.WriteLine("1): sudėtis (+)");
- Console.WriteLine("2): atimtis (-)");
- Console.WriteLine("3): daugyba (*)");
- Console.WriteLine("4): dalyba (/)");
- Console.WriteLine("-----------------------");
- }
- private static void Addition (double a, double b) => Console.WriteLine($"{a,0:f} + {b,0:f} = {(double)(a + b),0:f}");
- private static void Subraction (double a, double b) => Console.WriteLine($"{a,0:f} - {b,0:f} = {(double)(a - b),0:f}");
- private static void Multiplication (double a, double b) => Console.WriteLine($"{a,0:f} * {b,0:f} = {(double)(a * b),0:f}");
- private static void Devision (double a, double b)
- {
- try
- {
- Console.WriteLine($"{a,0:f} / {b,0:f} = {(double)(a / b),0:f}");
- }
- catch (Exception)
- {
- Console.WriteLine("Problema su Dalyba");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement