Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.78 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 prosty_kalkulator
  8. {
  9.     class Program
  10.     {
  11.         static void Dodaj()
  12.         {
  13.  
  14.             try
  15.             {
  16.  
  17.                 string argument1, argument2;
  18.                 Console.Write("Podaj argument 1: ");
  19.                 argument1 = Console.ReadLine();
  20.                 int arg1 = Convert.ToInt32(argument1);
  21.  
  22.                 Console.Write("Podaj argument 2: ");
  23.                 argument2 = Console.ReadLine();
  24.                 int arg2 = Convert.ToInt32(argument2);
  25.  
  26.                 int wynik = arg1 + arg2;
  27.  
  28.                 Console.WriteLine("wynik :  " + wynik);
  29.  
  30.             }
  31.  
  32.             catch (FormatException)
  33.             {
  34.                 Console.WriteLine("NIE WOLNO PODAWAĆ LITER!!!!!!!!!");
  35.             }
  36.  
  37.             Console.ReadKey();
  38.         }
  39.  
  40.         //**************************************************************************************************************
  41.  
  42.         static void Odejmij()
  43.         {
  44.  
  45.             try
  46.             {
  47.  
  48.                 string argument1, argument2;
  49.                 Console.Write("Podaj argument 1 : ");
  50.                 argument1 = Console.ReadLine();
  51.                 int arg1 = Convert.ToInt32(argument1);
  52.  
  53.                 Console.Write("Podaj argument 2 : ");
  54.                 argument2 = Console.ReadLine();
  55.                 int arg2 = Convert.ToInt32(argument2);
  56.  
  57.                 int wynik = arg1 - arg2;
  58.  
  59.                 Console.WriteLine("wynik :  " + wynik);
  60.  
  61.             }
  62.  
  63.             catch (FormatException)
  64.             {
  65.                 Console.WriteLine("NIE WOLNO PODAWAĆ LITER!!!!!!!!!");
  66.             }
  67.  
  68.             Console.ReadKey();
  69.         }
  70.  
  71.         //**************************************************************************************************************
  72.  
  73.         static void Pomnuż()
  74.         {
  75.             try
  76.             {
  77.                 string argument1, argument2;
  78.                 Console.Write("Podaj argument 1 : ");
  79.                 argument1 = Console.ReadLine();
  80.                 int arg1 = Convert.ToInt32(argument1);
  81.  
  82.                 Console.Write("Podaj argument 2 : ");
  83.                 argument2 = Console.ReadLine();
  84.                 int arg2 = Convert.ToInt32(argument2);
  85.  
  86.                 int wynik = arg1 * arg2;
  87.  
  88.                 Console.WriteLine("wynik :  " + wynik);
  89.  
  90.             }
  91.  
  92.             catch (FormatException)
  93.             {
  94.                 Console.WriteLine("NIE WOLNO PODAWAĆ LITER!!!!!!!!!");
  95.             }
  96.  
  97.             Console.ReadKey();
  98.         }
  99.  
  100.         //**************************************************************************************************************
  101.  
  102.         public static void Podziel()
  103.         {
  104.             try
  105.             {
  106.  
  107.                 string argument1, argument2;
  108.                 Console.Write("Podaj argument 1 : ");
  109.                 argument1 = Console.ReadLine();
  110.                 int arg1 = Convert.ToInt32(argument1);
  111.  
  112.                 Console.Write("Podaj argument 2 : ");
  113.                 argument2 = Console.ReadLine();
  114.                 int arg2 = Convert.ToInt32(argument2);
  115.  
  116.  
  117.                 int sprawdzenie = 30 / arg2;
  118.  
  119.                 double wynik = (double)arg1 / arg2;
  120.                 Console.WriteLine("wynik :  " + wynik);
  121.  
  122.  
  123.             }
  124.                  
  125.  
  126.             catch (DivideByZeroException)
  127.             {
  128.                 Console.WriteLine("NIE WOLNO DZIELIĆ PRZEZ 0!!!!!!!!!!!!!!!");
  129.             }
  130.  
  131.             catch (FormatException)
  132.             {
  133.                 Console.WriteLine("NIE WOLNO PODAWAĆ LITER!!!!!!!!!");
  134.             }
  135.  
  136.  
  137.             Console.ReadKey();
  138.         }
  139.  
  140.  
  141.         //**************************************************************************************************************
  142.  
  143.         static void Main(string[] args)
  144.         {
  145.             string lacwejsciowy = " ";
  146.  
  147.  
  148.  
  149.             do
  150.             {
  151.                 Console.Clear();
  152.                 Console.WriteLine("****************** KALKULATOR **************");
  153.                 Console.WriteLine("*                                          *");
  154.                 Console.WriteLine("*      Dodawanie     - nacisnij +          *");
  155.                 Console.WriteLine("*      Odejmowanie   - nacisnij -          *");
  156.                 Console.WriteLine("*      Mnożenie      - nacisnij *          *");
  157.                 Console.WriteLine("*      Dzielenie     - nacisnij /          *");
  158.                 Console.WriteLine("*      Koniec        - nacisnij k          *");
  159.                 Console.WriteLine("*                                          *");
  160.                 Console.WriteLine("********************************************");
  161.                 lacwejsciowy = Console.ReadLine();
  162.                 Console.Clear();
  163.  
  164.  
  165.                 //**************************************************************************************************************
  166.  
  167.  
  168.                 switch (lacwejsciowy)
  169.                 {
  170.                     case "+":
  171.                         {
  172.                             Console.WriteLine("---------------------------");
  173.                             Console.WriteLine("**** Wybrano dodawanie ****");
  174.                             Console.WriteLine("---------------------------");
  175.                             Dodaj();
  176.                             break;
  177.                         }
  178.                     case "-":
  179.                         {
  180.                             Console.WriteLine("----------------------------");
  181.                             Console.WriteLine("**** Wybrano odejmowanie ****");
  182.                             Console.WriteLine("----------------------------");
  183.                             Odejmij();
  184.                             break;
  185.                         }
  186.                     case "*":
  187.                         {
  188.                             Console.WriteLine("--------------------------");
  189.                             Console.WriteLine("**** Wybrano mnożenie ****");
  190.                             Console.WriteLine("--------------------------");
  191.                             Pomnuż();
  192.                             break;
  193.                         }
  194.                     case "/":
  195.                         {
  196.                             Console.WriteLine("---------------------------");
  197.                             Console.WriteLine("**** Wybrano dzielenie ****");
  198.                             Console.WriteLine("---------------------------");
  199.                             Podziel();
  200.                             break;
  201.                         }
  202.  
  203.                 }
  204.  
  205.                 //**************************************************************************************************************
  206.  
  207.             } while (lacwejsciowy != "k");
  208.         }
  209.     }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement