-
calculating cos
ok to really surprise my mom im doing all the basic windows
application (dont ask wut)
ok now im having a problem with the calculator
Code:
#include<iostream>
using namespace std;
int main()
{
int x;
int y;
int input;
do{
cout<<"1. multiply\n";
cout<<"2. devide\n";
cout<<"3. addition\n";
cout<<"4. subtraction\n";
cout<<"5. percentage\n";
cout<<"6. cos&sin\n";
cout<<"please provide the number listed\n";
cin>> input;
switch ( input )
{
case 1:
cout<<"please provide 2 numbers to be multiplied\n";
cin>> x >> y ;
cin.ignore();
cout<<( x*y );
cin.get();
break;
case 2:
cout<<"please provide 2 numbers to be devided\n";
cin>> x >> y ;
cin.ignore();
cout<<( x/y );
cin.get();
break;
case 3:
cout<<"pls provide 2 numbers to be added\n";
cin>> x >> y ;
cin.ignore();
cout<<( x+y );
cin.get();
break;
case 4:
cout<<"pls provide 2 numbers to be subtracted\n";
cin>> x >> y ;
cin.ignore();
cout<<( x-y );
cin.get();
break;
case 5:
cout<<"pls provide 2 numbers to percented\n";
cin>> x >> y ;
cin.ignore();
cout<<( x%y );
cin.get();
break;
case 6:
cout<<"pls provide 2 numbers to be cos\n";
cin>> x >> y ;
cin.ignore();
cout<<( cos(x, y );
cin.get();
break;
}
}while(input!=4);
}
but how do i do cos i dont get it
-
Try using indentation.
For cos you need to include <cmath>.
-
Maybe you want to make that whatever number you want to use for "quit"? Right now 4 invokes Subtraction.
-
sine, cosine, and tangent (sin(), cos(), and tan()) require one argument - an angle. The angle is measured in radians. That argument should be a double (since you will be using pi in any sensible angle), and the return value of sin(), cos() and tan() is a double.
A rewiew of one's trigonometric ratios might help.
And the little 'percentage' operator (modulus) returns the remainer of a division. ie, 5 % 3 = 2 (Since 5 / 3 = 1r2)
Also keep in mine you're using integers the whole way through. The user will not be able to enter a rational number, such as 1.526. I suggest looking into floating point numbers. Operations such as 20/9 will equal 2.
-
ok im thirteen anyone want to dumb it down
-
Ok in your case, you probably want to find the sin and cosin of (x)
in degrees rather than radians.
1 radian is equal to 180/pi degrees, i.e. about 57.3 degrees.
Therefore in order to use this in your calculator all you have to do is something like the following.
Code:
#include<iostream>
#include<math.h>
using namespace std;
{
double x;
cin>>x;
x=x/57.3;
cout<<sin(x);
cout<<cos(x);
.....
}
sin (x) is also defined as the infinite sum of:
Code:
x - x^3 + x^5 - x^7 +
----- ----- ----- ....
3! 5! 7!
However, in your case you probably don't need to worry about this.