Advertisement
Guest User

SimpleCalculator

a guest
Jan 16th, 2016
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.98 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 SimpleCalculator
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Title = "Simple Calculator by M0dEx";
  14.  
  15.             while(true)
  16.             {
  17.                 Console.Clear();
  18.  
  19.                 Console.WriteLine("Zadejte příklad(1 + 1, 2 - 2, ...):");
  20.                 string input = Console.ReadLine();
  21.                 try
  22.                 {
  23.                     string[] calculation = input.Split(' ');
  24.                     double a = Double.Parse(calculation[0]);
  25.                     double b = Double.Parse(calculation[2]);
  26.                     double result = 0;
  27.  
  28.                     switch(calculation[1])
  29.                     {
  30.                         case "+":
  31.                             result = a + b;
  32.                             break;
  33.                         case "-":
  34.                             result = a - b;
  35.                             break;
  36.                         case "*":
  37.                             result = a * b;
  38.                             break;
  39.                         case "/":
  40.                             result = a / b;
  41.                             break;
  42.                         default:
  43.                             Console.Clear();
  44.                             Console.WriteLine("Zadali jste špatnou početní operaci(+ = Sčítání, - = Odčítání, * = Násobení, / = Dělení)");
  45.                             continue;
  46.                     }
  47.  
  48.                     Console.Clear();
  49.                     Console.WriteLine("Výsledek je {0}!", result);
  50.  
  51.                 }
  52.                 catch (Exception ex)
  53.                 {
  54.                     Console.Clear();
  55.                     Console.WriteLine(ex.Message);
  56.                 }
  57.                 finally
  58.                 {
  59.                     Console.ReadLine();
  60.                 }
  61.             }
  62.         }
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement