Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.94 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.                 float arg1 = Convert.ToInt32(argument1);
  111.  
  112.                 Console.Write("Podaj argument 2 : ");
  113.                 argument2 = Console.ReadLine();
  114.                 float arg2 = Convert.ToInt32(argument2);
  115.  
  116.  
  117.                 float wynik = arg1 / arg2;
  118.  
  119.  
  120.                 if (arg2 == 0)
  121.                 {
  122.                     Console.WriteLine("NIE DZIELIMY PRZEZ 0");
  123.                     goto koniec;
  124.                 }
  125.  
  126.                 Console.WriteLine("wynik :  " + wynik);
  127.  
  128.             }
  129.  
  130.          /* catch (DivideByZeroException)
  131.             {
  132.               nie_dziel:
  133.                 Console.WriteLine("NIE WOLNO DZIELIĆ PRZEZ 0!!!!!!!!!!!!!!!");
  134.             }
  135.            */
  136.             catch (FormatException)
  137.             {
  138.                 Console.WriteLine("NIE WOLNO PODAWAĆ LITER!!!!!!!!!");
  139.             }
  140.             koniec:
  141.             Console.ReadKey();
  142.         }
  143.  
  144.  
  145.         //**************************************************************************************************************
  146.  
  147.         static void Main(string[] args)
  148.         {
  149.             string lacwejsciowy = " ";
  150.  
  151.  
  152.  
  153.             do
  154.             {
  155.                 Console.Clear();
  156.                 Console.WriteLine("****************** KALKULATOR **************");
  157.                 Console.WriteLine("*                                          *");
  158.                 Console.WriteLine("*      Dodawanie     - nacisnij +          *");
  159.                 Console.WriteLine("*      Odejmowanie   - nacisnij -          *");
  160.                 Console.WriteLine("*      Mnożenie      - nacisnij *          *");
  161.                 Console.WriteLine("*      Dzielenie     - nacisnij /          *");
  162.                 Console.WriteLine("*      Koniec        - nacisnij k          *");
  163.                 Console.WriteLine("*                                          *");
  164.                 Console.WriteLine("********************************************");
  165.                 lacwejsciowy = Console.ReadLine();
  166.                 Console.Clear();
  167.  
  168.  
  169.                 //**************************************************************************************************************
  170.  
  171.  
  172.                 switch (lacwejsciowy)
  173.                 {
  174.                     case "+":
  175.                         {
  176.                             Console.WriteLine("---------------------------");
  177.                             Console.WriteLine("**** Wybrano dodawanie ****");
  178.                             Console.WriteLine("---------------------------");
  179.                             Dodaj();
  180.                             break;
  181.                         }
  182.                     case "-":
  183.                         {
  184.                             Console.WriteLine("----------------------------");
  185.                             Console.WriteLine("**** Wybrano odejmowanie ****");
  186.                             Console.WriteLine("----------------------------");
  187.                             Odejmij();
  188.                             break;
  189.                         }
  190.                     case "*":
  191.                         {
  192.                             Console.WriteLine("--------------------------");
  193.                             Console.WriteLine("**** Wybrano mnożenie ****");
  194.                             Console.WriteLine("--------------------------");
  195.                             Pomnuż();
  196.                             break;
  197.                         }
  198.                     case "/":
  199.                         {
  200.                             Console.WriteLine("---------------------------");
  201.                             Console.WriteLine("**** Wybrano dzielenie ****");
  202.                             Console.WriteLine("---------------------------");
  203.                             Podziel();
  204.                             break;
  205.                         }
  206.  
  207.                 }
  208.  
  209.                 //**************************************************************************************************************
  210.  
  211.             } while (lacwejsciowy != "k");
  212.         }
  213.     }
  214. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement