Advertisement
Cassimus

Kalkulator

Feb 25th, 2025
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. public class Kalkulator
  2. {
  3.     public static void Main(string[] args)
  4.     {
  5.         float liczba1, liczba2;
  6.  
  7.         System.Console.WriteLine("Podaj pierwszą liczbę");
  8.         liczba1 = float.Parse(Console.ReadLine());
  9.  
  10.         System.Console.WriteLine("Podaj drugą liczbę");
  11.         liczba2 = float.Parse(Console.ReadLine());
  12.  
  13.         System.Console.WriteLine("1. Dodawanie\n2. Odejmowanie\n3. Mnożenie\n4. Dzielenie");
  14.         int operacja = int.Parse(Console.ReadLine());
  15.  
  16.         if(operacja == 1)
  17.         {
  18.             System.Console.WriteLine($"{liczba1} + {liczba2} = {liczba1 + liczba2}");
  19.         }
  20.         else if(operacja == 2)
  21.         {
  22.             // odejmowanie
  23.         }
  24.         else if (operacja == 3)
  25.         {
  26.             //mnożenie
  27.         }
  28.         else if (operacja == 4)
  29.         {
  30.             if (liczba2 == 0)
  31.             {
  32.                 System.Console.WriteLine("Nie mogę dzielić przez zero");
  33.             }
  34.             else
  35.             {
  36.                 System.Console.WriteLine($"{liczba1} / {liczba2} = {liczba1 / liczba2}");
  37.             }
  38.         }
  39.         else
  40.         {
  41.             System.Console.WriteLine("Nioe znam takiego działania");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement