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 SimpleCalculator
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Title = "Simple Calculator by M0dEx";
- while(true)
- {
- Console.Clear();
- Console.WriteLine("Zadejte příklad(1 + 1, 2 - 2, ...):");
- string input = Console.ReadLine();
- try
- {
- string[] calculation = input.Split(' ');
- double a = Double.Parse(calculation[0]);
- double b = Double.Parse(calculation[2]);
- double result = 0;
- switch(calculation[1])
- {
- case "+":
- result = a + b;
- break;
- case "-":
- result = a - b;
- break;
- case "*":
- result = a * b;
- break;
- case "/":
- result = a / b;
- break;
- default:
- Console.Clear();
- Console.WriteLine("Zadali jste špatnou početní operaci(+ = Sčítání, - = Odčítání, * = Násobení, / = Dělení)");
- continue;
- }
- Console.Clear();
- Console.WriteLine("Výsledek je {0}!", result);
- }
- catch (Exception ex)
- {
- Console.Clear();
- Console.WriteLine(ex.Message);
- }
- finally
- {
- Console.ReadLine();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement