//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>
usingnamespace 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...