Advertisement
_crimsonghost

Homework 20190917 - Kalkulator

Sep 18th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.32 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. float addition(float A, float B);
  6. float substraction(float A, float B);
  7. float multiplication(float A, float B);
  8. float division(float A, float B);
  9.  
  10. void main()
  11. {
  12.     float Left = 0.f;
  13.     float Right = 0.f;
  14.     float Result = 0.f;
  15.     char Operation = '+';
  16.  
  17.     cout << "Podaj pierwsza liczbe: ";
  18.     cin >> Left;
  19.     cout << endl;
  20.  
  21.     cout << "Wybierz rodzaj dzialania uzywajac znakow: +, -, * lub /." << endl << "Rodzaj dzialania: ";
  22.     cin >> Operation;
  23.     cout << endl;
  24.  
  25.     cout << "Podaj druga liczbe: ";
  26.     cin >> Right;
  27.     cout << endl;
  28.  
  29.     if (Operation == '+')
  30.     {
  31.         Result = addition(Left, Right);
  32.     }
  33.  
  34.     else if (Operation == '-')
  35.     {
  36.         Result = substraction(Left, Right);
  37.     }
  38.  
  39.     else if (Operation == '*')
  40.     {
  41.         Result = multiplication(Left, Right);
  42.     }
  43.  
  44.     else if (Operation == '/')
  45.         if (Right == 0)
  46.         {
  47.             cout << "Nie dziel cholero przez zero!" << endl;
  48.         }
  49.         else
  50.         {
  51.             Result = division(Left, Right);
  52.         }
  53.  
  54.     if (Right != 0)
  55.     {
  56.         cout << "Rozwiazanie: " << Left << Operation << Right << '=' << Result << endl;
  57.     }
  58.     system("PAUSE");
  59. }
  60.  
  61. float addition(float A, float B)
  62. {
  63.     return A + B;
  64. }
  65.  
  66. float substraction(float A, float B)
  67. {
  68.     return A - B;
  69. }
  70.  
  71. float multiplication(float A, float B)
  72. {
  73.     return A * B;
  74. }
  75.  
  76. float division(float A, float B)
  77. {
  78.     return A / B;
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement