Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. //zad3 kalkulator
  2.  
  3. #include "stdafx.h"
  4. #include <conio.h>
  5.  
  6. float Dodaj(float x, float y)
  7. {
  8.     float wynik = x + y;
  9.     return wynik;
  10. }
  11.  
  12. float Odejmij(float x, float y)
  13. {
  14.     float wynik = x - y;
  15.     return wynik;
  16. }
  17.  
  18. float Pomnoz(float x, float y)
  19. {
  20.     float wynik = x * y;
  21.     return wynik;
  22. }
  23.  
  24. float Podziel(float x, float y)
  25. {
  26.     float wynik = x / y;
  27.     return wynik;
  28. }
  29.  
  30. int main()
  31. {
  32.     float x = 0, y = 0;
  33.     char z = '+', next = 'x';
  34.     do
  35.     {
  36.         printf("Podaj dwie liczby:\r\n");
  37.         scanf_s("%f", &x);
  38.         scanf_s("%f", &y);
  39.         printf("Twoje liczby to: %f oraz %f.\r\n", x, y);
  40.         printf("Podaj znak dzia�ania kt�e chcesz wykonac\r\n");
  41.         z = _getch();
  42.  
  43.         float wynik;
  44.  
  45.         switch (z)
  46.         {
  47.         case '+':
  48.             wynik = Dodaj(x, y);
  49.             break;
  50.         case '-':
  51.             wynik = Odejmij(x, y);
  52.             break;
  53.         case '*':
  54.             wynik = Pomnoz(x, y);
  55.             break;
  56.         case '/':
  57.             wynik = Podziel(x, y);
  58.             break;
  59.         }
  60.  
  61.         printf("Wynik dzialania to %f\r\n", wynik);
  62.  
  63.         printf("Wpisz 1 zeby zaczac od poczatku, albo cokolwiek zeby wyjsc\r\n");
  64.         next = _getch();
  65.  
  66.     }
  67.     while (next == '1');
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement