Guys check this calculator

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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//tell me how i should i improve it
//--------------------------------------------|
//Made by Behzad Khoker                       |  

//Calculator with functions                   |
//Version 1.0(Beta)  //Please tell me how should i make it better|
//---------------------------------------------
#include <iostream>
#include <math.h>
using namespace std;
//Operation starts here------------------------------------------
void sum(){
cout<<"Enter a number"<<endl;
int num,num2,ans;
cin>>num;
cout<<"Enter another number"<<endl;
cin>>num2;
ans=num+num2;
cout<<"The answer is "<<ans<<endl;
}
void subtract(){
cout<<"Enter a large number"<<endl;
int num,num2,ans;
cin>>num;
cout<<"Enter a small number"<<endl;
cin>>num2;
ans=num-num2;
cout<<"The answer is "<<ans<<endl;

}
void multiply(){

	cout<<"Enter a number"<<endl;
int num,num2,ans;
cin>>num;
cout<<"Enter another number"<<endl;
cin>>num2;
ans=num*num2;
cout<<"The answer is "<<ans<<endl;




}
void divide(){
cout<<"Enter a large number"<<endl;
int num,num2,ans;
cin>>num;
cout<<"Enter a small number"<<endl;
cin>>num2;
ans=num/num2;
cout<<"The answer is "<<ans<<endl;



}
void sin(){
cout<<"1)sin 2)cos 3)tan"<<endl;
int enter;
float num;
cin>>enter;
switch (enter)
{
case 1:
	cout<<"enter a number"<<endl;
	cin>>num;
	cout<<"sin "<<num<<" is"<<sin(num);
	break;
case 2:
	cout<<"enter a number"<<endl;
	cin>>num;
	cout<<"cos "<<num<<" is"<<cos(num);
	break;
case 3:
	cout<<"enter a number"<<endl;
	cin>>num;
	cout<<"tan "<<num<<" is"<<tan(num);
	break;
default:
	cout<<"Error"<<endl;
	break;
}


}
void calculator(){
do{ system("cls");
		int ent;
cout<<"What do you want to do \n1)add \n2)subtract \n3)multiply \n4)divide\n5)cos,tan,sin \n------------------------------------------------"<<endl;
	cin>>ent;
	switch (ent)
	{
	case 1:
		sum();
		break;
	case 2:
		subtract();
		break;
	case 3:
		multiply();
		break;
	case 4:
		divide();
		break;
	case 5:
		sin();
		break;
	default:
		cout<<"invalid\n";
		break;}
system("pause");
	}while(1);
}
//Operation Ends here------------------------------------------

void main(){
	calculator();
}

//By Behzad Khoker 


Don't allow user to divide by 0. Subtract can give negative answers (i.e. It doesn't need a larger first number). You don't need math.h for anything you're doing here and should change it to <cmath>. However, you could use it to square root numbers sqrt(n) or raise numbers to powers pow(n,p). I would suggest changing every int to doubles so you can have non-integers too.

A few suggestions, though there are many other improvements you can make...
Thankyou mats
Topic archived. No new replies allowed.