VonFuzzball
April 9th, 2011, 07:19 PM
I've just recently started learning C programming, and I'm trying to create a program that asks for an angle theta, in radians, from the user and then reports either the value of sin(theta) or cos(theta), depending on which one has the smaller absolute value.
My code is this:
#include <stdio.h>
#include <math.h>
int main (void)
{
double angle, angle2, theta;
printf("Enter the angle, theta, in radians:");
scanf("%lf",&theta);
angle = sin(theta);
angle2 = cos(theta);
if (angle < angle2)
{ printf("Value of sin(theta) is %g"); }
else
{ printf ("Value of cos(theta) is %g"); }
}The program will compile and run, but it doesn't do what I want it to. As a matter of fact, it returns the same incorrect number regardless of what value I enter for the angle. Any help would be appreciated!
My code is this:
#include <stdio.h>
#include <math.h>
int main (void)
{
double angle, angle2, theta;
printf("Enter the angle, theta, in radians:");
scanf("%lf",&theta);
angle = sin(theta);
angle2 = cos(theta);
if (angle < angle2)
{ printf("Value of sin(theta) is %g"); }
else
{ printf ("Value of cos(theta) is %g"); }
}The program will compile and run, but it doesn't do what I want it to. As a matter of fact, it returns the same incorrect number regardless of what value I enter for the angle. Any help would be appreciated!