Advertisement
Cassimus

debug

Mar 29th, 2025
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. public class Lekcja8
  2. {
  3.     public static void Main(string[] args)
  4.     {
  5.         System.Console.WriteLine("Cześć! Jak masz na imię?");
  6.         string? imie = Console.ReadLine();
  7.  
  8.         if (imie == null) return;
  9.  
  10.         System.Console.WriteLine($"Witaj {imie.ToUpper()}. Co Chcesz robić?: ");
  11.         System.Console.WriteLine("a. dodawanie \nb. odejmowanie \nc. mnożenie \nd. dzielenie");
  12.  
  13.         string? wybor = Console.ReadLine();
  14.         if (wybor == null) return;
  15.  
  16.         Console.Write("Podaj pierwszą liczbę: ");
  17.         int liczba1;
  18.  
  19.         try
  20.         {
  21.             liczba1 = int.Parse(Console.ReadLine()!);
  22.         }
  23.         catch (FormatException format)
  24.         {
  25.             System.Console.WriteLine("Podana wartość nie jest liczbą");
  26.             System.Console.WriteLine(format.Message);
  27.             return;
  28.         }
  29.         catch (Exception)
  30.         {
  31.             System.Console.WriteLine("Coś poszlo nie tak");
  32.             return;
  33.         }
  34.  
  35.         int liczba2;
  36.         bool parsowanie = int.TryParse(Console.ReadLine(), out liczba2);
  37.  
  38.         if (!parsowanie)
  39.         {
  40.             System.Console.WriteLine("To nie jest liczba");
  41.             return;
  42.         }
  43.  
  44.         System.Console.WriteLine($"Podałeś liczbę: {liczba1}");
  45.  
  46.     }
  47. }
  48.  
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement