-
Notifications
You must be signed in to change notification settings - Fork 0
/
simplecalculator.cpp
41 lines (36 loc) · 971 Bytes
/
simplecalculator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <iostream>
using namespace std;
void calculator(float a, float b)
{
int x;
do
{
cout << "1-add,2-sub,3-mul,4-div" << endl;
float c;
cin >> c;
if (c == 1)
cout << "its addition of two numbers" << endl
<< a + b<<endl;
else if (c == 2)
cout << "its subtraction" << endl
<< a - b<<endl;
else if (c == 3)
cout << "its multiplication" << endl
<< a * b<<endl;
else if (c == 4)
if (b != 0)
cout << "its division" << endl
<< (float)a / b<<endl;
else
cout << "div by 0 or not defined"<<endl;
cout << "enter 0 to exit" << endl;
cin >> x;
} while (x != 0);
}
main()
{
float a, b, c;
cout << "enter two numbers" << endl;
cin >> a >> b;
calculator(a, b);
}