Advertisement
MeehoweCK

Untitled

Oct 30th, 2020
1,802
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. void dodawanie(int a, int b)
  7. {
  8.     cout << a << " + " << b << " = " << a + b << endl;
  9. }
  10.  
  11. void odejmowanie(int a, int b)
  12. {
  13.     cout << a << " - " << b << " = " << a - b << endl;
  14. }
  15.  
  16. void mnozenie(int a, int b)
  17. {
  18.     cout << a << " * " << b << " = " << a * b << endl;
  19. }
  20.  
  21. void dzielenie(int a, int b)
  22. {
  23.     if(b == 0)
  24.         cout << "Dzialanie niedostepne. Nie mozna dzielic przez 0.\n";
  25.     else
  26.         cout << a << " / " << b << " = " << 1.0 * a / b << endl;
  27. }
  28.  
  29. int main()
  30. {
  31.     cout << "Podaj dwie liczby calkowite: ";
  32.     int a, b;
  33.     cin >> a >> b;
  34.  
  35.     // MENU:
  36.     cout << "Wybierz odpowiednie dzialanie:\n";
  37.     cout << "\t1 - dodawanie\n";
  38.     cout << "\t2 - odejmowanie\n";
  39.     cout << "\t3 - mnozenie\n";
  40.     cout << "\t4 - dzielenie\n";
  41.     cout << "\t0 - wyjdz z programu\n";
  42.  
  43.     char znak;
  44.  
  45.     // pobranie decyzji od użytkownika:
  46.     do
  47.     {
  48.         znak = getch();
  49.     } while(znak < '0' || znak > '4');
  50.  
  51.     switch (znak)
  52.     {
  53.     case '0':
  54.         return 0;
  55.     case '1':
  56.         dodawanie(a, b);
  57.         break;
  58.     case '2':
  59.         odejmowanie(a, b);
  60.         break;
  61.     case '3':
  62.         mnozenie(a, b);
  63.         break;
  64.     case '4':
  65.         dzielenie(a, b);
  66.     }
  67.  
  68.     cout << "Wcisnij dowolny klawisz...";
  69.     getch();
  70.     system("cls");
  71.     main();
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement