1.2 Calculator in c++ by behzad khoker

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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//By behzad khoker
//Beta (1.2)
//Please reply and tell me what sholud do to improve this
//---------------------------------------------
#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 temperature(){
float c,f;
cout << "Enter Temperature in Fahrenheit : ";
cin >>f;
c = (f - 32)*5/9;
cout << f<<" Fahrenheit temperature is equal to Centigrade = " << c;
}
void equation(){
	float a,b,c,ans;
	cout<<"Enter A"<<endl;
	cin>>a;
	cout<<"enter B"<<endl;
	cin>>b;
	cout<<"Enter c"<<endl;
	cin>>c;
	ans= (-b + sqrt( b*b - ( 4*a*c ))) / (2 * a) ;
	cout<<"X ="<<ans<<endl;
}
void calculator(){
do{ system("cls");
		int ent;
	cout<<endl<<"What do you want to do \n1)add \n2)subtract \n3)multiply \n4)divide\n5)cos,tan,sin\n6)temperature conversion\n7)quadratic equation \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;
	case 6:
		temperature();
		break;
	case 7:
		equation();
		break;
	default:
		cout<<"invalid\n";
		break;}
system("pause");
	}while(1);
}
//Operation Ends here------------------------------------------

void main(){
	calculator();
}
//------------------------------------------------------------------------------------------







What's the problem with it that you want us to help fix?
OP didn't actually post this as a question.
I want to know how to add colors to the text;
behzadkhoker .. if you want to add color to the text you will need to include this

#include <stdlib.h>
and use functions -> system("COLOR 0B");

take a look in here;

http://www.cplusplus.com/forum/beginner/1640/

OR here

0 = Black
1 = Blue
2 = Green
3 = Aqua
4 = Red
5 = Purple
6 = Yellow
7 = White
8 = Gray
9 = Light Blue
A = Light Green
B = Light Aqua
C = Light Red
D = Light Purple
E = Light Yellow
F = Bright White

For example if you use system("COLOR 1A"); you will get a Blue background and Light green text
Topic archived. No new replies allowed.