-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calculator assignment.cpp
89 lines (88 loc) · 1.97 KB
/
Calculator assignment.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
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
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
int age();
int square_root();
int main()
{
char a;
int x,y;
float c,d;
cout<<endl<<"****---- Welcome to my Calculator written by Asad ----****"<<endl;
cout<<"\nWhich task you want to perform (+,-,*,/)"<<endl;
cout<<"Age Calculator\t\t(press c)"<<endl;
cout<<"Square Root\t\t(press s)"<<endl;
cin>>a;
if(a=='+' || a=='-' || a=='*' || a=='/')
{
switch(a)
{
case '+':
cout<<"*******\t\tAddition\t*******"<<endl<<endl;
cout<<"Enter 1st number:\t";
cin>>x;
cout<<"Enter 2nd number:\t";
cin>>y;
cout<<"---------------------------"<<endl<<"The answer is\t:\t"<<x+y;
break;
case '-':
cout<<"*******\t\tSubtraction\t*******"<<endl<<endl;
cout<<"Enter 1st number:\t";
cin>>x;
cout<<"Enter 2nd number:\t";
cin>>y;
cout<<"---------------------------"<<endl<<"The answer is\t:\t"<<x-y;
break;
case '*':
cout<<"*******\t\tMultiplication\t*******"<<endl<<endl;
cout<<"Enter 1st number:\t";
cin>>x;
cout<<"Enter 2nd number:\t";
cin>>y;
cout<<"---------------------------"<<endl<<"The answer is\t:\t"<<x*y;
break;
case '/':
cout<<"*******\t\tDivision\t*******"<<endl<<endl;
cout<<"Enter 1st number:\t";
cin>>c;
cout<<"Enter 2nd number:\t";
cin>>d;
cout<<"---------------------------"<<endl<<"The answer is\t:\t"<<c/d;
break;
}
cout<<endl<<endl;
}
else if(a=='c')
{
age();
}
else if(a=='s')
{
square_root();
}
else
cout<<"Error";
getch();
}
int age()
{
int days,months,age;
cout<<"*******\tAge Calculator\t*******"<<endl<<endl;
cout<<"How old are you? ";
cin>>age;
days=age*365;
months=age*12;
cout<<"---------------------------"<<endl;
cout<<"Your age in days\t : "<<days<<endl;
cout<<"your age in Months : "<<months<<endl;
}
int square_root()
{
int n;
cout<<"*******\tSquare Root\t*******"<<endl<<endl;
cout<<"Enter Number : ";
cin>>n;
cout<<"---------------------------"<<endl;
cout<<"The Square Root of "<<n<<" is "<<sqrt(n);
}