Cassimus

Kod poprawiony

Oct 17th, 2025
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1.  
  2. internal class Program
  3. {
  4. private static void Main(string[] args)
  5. {
  6. Console.WriteLine("Prosty kalkulator");
  7. Console.WriteLine("Podaj numer działania: ");
  8. Console.WriteLine("1. Dodawanie");
  9. Console.WriteLine("2. Odejmowanie");
  10. Console.WriteLine("3. Mnożenie");
  11. Console.WriteLine("4.Dzielenie");
  12.  
  13. int wybor = int.Parse(Console.ReadLine()??"0");
  14.  
  15. Console.WriteLine("podaj pierwszą liczbę");
  16. string? liczbaAString = Console.ReadLine();
  17. float liczbaA = 0;
  18. //if (liczbaAString != null)
  19. if (!string.IsNullOrWhiteSpace(liczbaAString))
  20. {
  21. liczbaA = float.Parse(liczbaAString);
  22. }
  23. else
  24. {
  25. liczbaA = 0;
  26. }
  27. Console.WriteLine("Podaj drugą liczbę");
  28.  
  29.  
  30. //float liczbaB = float.Parse(Console.ReadLine());
  31. if (float.TryParse(Console.ReadLine(), out float liczbaB))
  32. {
  33. switch (wybor)
  34. {
  35. case 1:
  36. Console.WriteLine($"Wynik: {liczbaA + liczbaB}");
  37. break;
  38. case 2:
  39. Console.WriteLine($"Wynik: {liczbaA - liczbaB}");
  40. break;
  41. case 3:
  42. Console.WriteLine($"Wynik: {liczbaA * liczbaB}");
  43. break;
  44. case 4:
  45. Console.WriteLine($"Wynik: {liczbaA / liczbaB}");
  46. break;
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment