Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <fstream>
- using namespace std;
- plik()
- {
- ofstream plik;
- plik.open("plik.txt");
- }
- void Podaj(double &a, double &b)
- {
- cout << "Podaj 2 liczby rzeczywiste: ";
- cin >> a >> b;
- }
- char menu()
- {
- cout << "Wybierz co chcesz zrobic:" << endl;
- cout << "* dodaj <1>" <<endl;
- cout << "* odejmij <2>" <<endl;
- cout << "* pomnoz <3>" <<endl;
- cout << "* podziel <4>" <<endl;
- cout << "* wyjdz z programu <0>" << endl;
- char wybor;
- do
- {
- wybor = getch();
- }
- while(wybor != '0' && wybor != '1' && wybor != '2' && wybor != '3' && wybor != '4');
- cout << wybor;
- return wybor;
- }
- void kalkulator()
- {
- double a, b;
- char wybor;
- do
- {
- wybor = menu();
- switch(wybor)
- {
- case '0':
- cout << " - wychodze z programu" << endl;
- return; // w funkcji typu void słowo kluczowe return nakazuje po prostu wyjście z funkcji
- case '1':
- cout << " - wybrales dodawanie. ";
- Podaj(a, b);
- cout << a << " + " << b << " = " << a+b << endl << endl;
- break;
- case '2':
- cout << " - wybrales odejmowanie. ";
- Podaj (a, b);
- cout << a << " - " << b << " = " << a-b <<endl << endl;
- break;
- case '3':
- cout << " - wybrales mnozenie. ";
- Podaj (a, b);
- cout << a << " * " << b << " = " << a*b <<endl << endl;
- break;
- case '4':
- cout << " - wybrales dzielenie. ";
- Podaj (a, b);
- while(b == 0)
- {
- cout << "Nie mozna dzielic przez 0!" << endl;
- Podaj(a, b);
- }
- cout << a << " / " << b << " = " << a/b <<endl << endl;
- break;
- }
- }
- while(true);
- }
- int main()
- {
- kalkulator();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement