Hi there Sin/Cos function...

Hi there. I am taking a beginners c++ course and having problems using the sin and cos functions. It's have problems converting to radians etc even with the formulas in it. It's probably a stupid mistake...

I'd appreciate if anyone could help out....thanks!

#include <stdio.h>
#include <math.h>

//Program body


int main()
{

double pi, r, theta, thetaRad, x ,y;

pi = 3.1415;
thetaRad = 0;


printf("Enter the value of r: ");
scanf("%d", &r);

printf("the value for r you entered was %d \n", r);

printf("Enter the value of the angle, theta: ");
scanf("%d", &theta);



printf("the value for theta you entered was %d\n", theta);

thetaRad = theta * pi / 180;



printf("the value for thetaRad you entered was %d\n", thetaRad);

x = r * cos(thetaRad);
y = r * sin(thetaRad);


printf("The rectangular coordinates are: %d , %d\n", x, y);



}


//End of program
the problem is with input/output.
%d is for decimal integers
for doubles use %lf, I think..
see http://www.cplusplus.com/reference/clibrary/cstdio/scanf/
Thank you! Works perfect.
Topic archived. No new replies allowed.