forked from ASD-ADF/ASD_Task_1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_calculator.cpp
More file actions
71 lines (64 loc) · 2.01 KB
/
simple_calculator.cpp
File metadata and controls
71 lines (64 loc) · 2.01 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//Created By Hizas Sabilal Rasyad / 1301140251
#include <iostream>
#include <conio.h>
#include <cmath>
#include <windows.h>
using namespace std;
void menu()
{
cout<<"=========================="<<endl;
cout<<"|| Klavier Calculator ||"<<endl;
cout<<"=========================="<<endl;
}
void legend()
{
cout<<"|| L || (1) Sum |"<<endl;
cout<<"|| E || (2) Minus |"<<endl;
cout<<"|| G || (3) Multiply |"<<endl;
cout<<"|| E || (4) Divide |"<<endl;
cout<<"|| N || (5) Power |"<<endl;
cout<<"|| D || (6) Root |"<<endl;
cout<<"=========================="<<endl;
cout<<endl;
}
double sum(double a, double b){return (a+b);}
double mins(double a, double b){return (a-b);}
double mult(double a, double b){return (a*b);}
double divi(double a, double b){return (a/b);}
double power(double a, double b){return (pow(a,b));}
double root(double a, double b){return pow(a,(1/b));}
int main()
{
char answer;
bool loop;
int oprtr;
double opr1, opr2;
menu();
legend();
do
{
loop = false;
cout<<"Operan 1 : "; cin>>opr1;
cout<<"Operator : "; cin>>oprtr;
cout<<"Operan 2 : "; cin>>opr2;
cout<<endl;
switch(oprtr)
{
case 1 : cout<<opr1<<" + "<<opr2<<" = "<<sum(opr1,opr2); break;
case 2 : cout<<opr1<<" - "<<opr2<<" = "<<mins(opr1,opr2); break;
case 3 : cout<<opr1<<" X "<<opr2<<" = "<<mult(opr1,opr2); break;
case 4 : cout<<opr1<<" : "<<opr2<<" = "<<divi(opr1,opr2); break;
case 5 : cout<<opr1<<" Power "<<opr2<<" = "<<power(opr1,opr2); break;
case 6 : cout<<opr1<<" Root "<<opr2<<" = "<<root(opr1,opr2); break;
}
cout<<endl;
cout<<"Again ?(Press Y for again)";
answer = _getch();
cout<<endl;
if ((answer == 'Y') or (answer == 'y')){ loop = true; cout<<endl; }
} while (loop == true);
system("cls");
cout<<"Thanks for using this app :)";
cout<<endl;
return 0;
}