Trigonometric functions

Hi There,

I am using this program to find values of some trigonometric functions. However, when I try to print (sin 90 for example) it gives me 0.893997 when in fact it should be 1. I tried other values and the same problem persists. What is the problem here. This is the code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
include <iostream>
# include <cmath>


using namespace std;

int main ()
{
int x, y;
y = 5/4;
int *p;
p = &x;
cin>> *p;
cin.ignore();
cout<< *p << "\n";
cout << sin (90) << "\n";
cin.get();

}



Any help is appreciated.
Last edited on
closed account (zwA4jE8b)
use radians not degrees
1
2
int x, y;
y = 5/4;


As an aside, note also that y is an int. If you want to store the actual value of 5/4 (i.e. 1.25) you're going to need to use a suitable type.
Ok. I modified the code slightly by changing to (float y) but it's still giving me y as 1 not 1.25. Why is that? Here it is again:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
# include <cmath>


using namespace std;

int main ()
{
int x;
float y;
y = 5/4;
int *p;
p = &x;
cin>> *p;
cin.ignore();
cout<< *p << "\n";
cout<< y << "\n";
cout << sin (0.785) << "\n";
cin.get();

}
closed account (zwA4jE8b)
try y = 5.0/4.0;
It worked. Thank you very much CreativeMFS and Moschops.

Topic archived. No new replies allowed.