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
|
#include <iostream>
#include <cmath>
using namespace std;
#define PI 3.14159265
int mult (int x, int y); //function declaration (there's going to be a function called mult)
int sub (int x, int y);
int div (int x, int y);
int add (int x, int y);
double cos (double x);
int tan (int x);
int sin (int x);
int main()
{
int f_choice;
int x, y;
cout<<" 1. mult \n 2. sub \n 3. div \n 4. add \n 5. cos \n 6. tan \n 7. sin \n";
cin >> f_choice;
switch ( f_choice ) {
case 1:
cout<<"Enter 2 numbers:\n";
cin>> x >> y;
mult(x,y);
break;
case 2:
cout<<"Enter 2 numbers:\n";
cin>> x >> y;
sub(x,y);
break;
case 3:
cout<<"Enter 2 numbers:\n";
cin>> x >> y;
div(x,y);
break;
case 4:
cout<<"Enter 2 numbers: \n";
cin>> x >> y;
add(x,y);
break;
case 5:
cout<<"Enter 1 number: \n";
cin>>x;
cos(x);
break;
case 6:
cout<<"Enter 1 number: \n";
cin>>x;
tan(x);
break;
case 7:
cout<<"Enter 1 number: \n";
cin>>x;
sin(x);
break;
default:
cout<<"Error, bad input, quitting\n";
break;
}
}
int mult ( int x, int y ) //declare variables x and y in function mult. since this is a new function, you can declare the vars whatever you like.
{
int z;
z = x * y;
cout<<x << "*" << y << "=" <<z;
}
int sub ( int x, int y )
{
int z;
z = x - y;
cout<<x << "-" << y << "=" <<z;
}
int div ( int x, int y )
{
int z;
z = x / y;
cout<<x << "/" << y << "=" <<z;
}
int add ( int x, int y )
{
int z;
z = x + y;
cout<<x << "+" << y << "=" <<z;
}
double cos ( double x )
{
{
double param, result;
param = x;
result = cos (param*PI/180);
cout<<"Cosine of "<< param <<"degrees is "<<result;
return 0;
}
}
int tan ( int x )
{
double param, result;
param = x;
result = tan (param*PI/180);
cout<<"Tangent of "<< param <<"degrees is "<<result;
return 0;
}
int sin ( int x )
{
double param, result;
param = x;
result = sin (param*PI/180);
cout<<"Sine of "<< param <<"degrees is "<<result;
return 0;
}
|