Advertisement
MeehoweCK

Untitled

Jul 23rd, 2018
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  plik()
  7. {
  8.     ofstream plik;
  9.     plik.open("plik.txt");
  10.  
  11.  
  12. }
  13.  
  14. void Podaj(double &a, double &b)
  15. {
  16.     cout << "Podaj 2 liczby rzeczywiste: ";
  17.     cin >> a >> b;
  18. }
  19.  
  20. char menu()
  21. {
  22.     cout << "Wybierz co chcesz zrobic:" << endl;
  23.     cout << "* dodaj <1>" <<endl;
  24.     cout << "* odejmij <2>" <<endl;
  25.     cout << "* pomnoz <3>" <<endl;
  26.     cout << "* podziel <4>" <<endl;
  27.     cout << "* wyjdz z programu <0>" << endl;
  28.  
  29.     char wybor;
  30.  
  31.     do
  32.     {
  33.         wybor = getch();
  34.     }
  35.     while(wybor != '0' && wybor != '1' && wybor != '2' && wybor != '3' && wybor != '4');
  36.  
  37.     cout << wybor;
  38.     return wybor;
  39. }
  40.  
  41. void kalkulator()
  42. {
  43.     double a, b;
  44.  
  45.     char wybor;
  46.  
  47.     do
  48.     {
  49.         wybor = menu();
  50.  
  51.         switch(wybor)
  52.         {
  53.         case '0':
  54.             cout << " - wychodze z programu" << endl;
  55.             return;                                         // w funkcji typu void słowo kluczowe return nakazuje po prostu wyjście z funkcji
  56.         case '1':
  57.             cout << " - wybrales dodawanie. ";
  58.             Podaj(a, b);
  59.             cout << a << " + " << b << " = " << a+b << endl << endl;
  60.             break;
  61.         case '2':
  62.             cout << " - wybrales odejmowanie. ";
  63.             Podaj (a, b);
  64.             cout << a << " - " << b << " = " << a-b <<endl << endl;
  65.             break;
  66.  
  67.         case '3':
  68.             cout << " - wybrales mnozenie. ";
  69.             Podaj (a, b);
  70.             cout << a << " * " << b << " = " << a*b <<endl << endl;
  71.             break;
  72.  
  73.         case '4':
  74.             cout << " - wybrales dzielenie. ";
  75.             Podaj (a, b);
  76.             while(b == 0)
  77.             {
  78.                 cout << "Nie mozna dzielic przez 0!" << endl;
  79.                 Podaj(a, b);
  80.             }
  81.                 cout << a << " / " << b << " = " << a/b <<endl << endl;
  82.             break;
  83.         }
  84.     }
  85.     while(true);
  86. }
  87.  
  88. int main()
  89. {
  90.     kalkulator();
  91.     return 0;
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement