Problem using tan() and cos() functions

This is a discussion on Problem using tan() and cos() functions within the C Programming forums, part of the General Programming Boards category; I have a small bit of code that should accept an input as a double and use that input value ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    2

    Problem using tan() and cos() functions

    I have a small bit of code that should accept an input as a double and use that input value in an equation with tan() and cos()...but it doesn't work and I don't know why. Here's my code:

    Code:
    #include <stdio.h>
    #include <math.h> 
    
    int main (void)
    {
            double theta = 0.0, sin_theta = 0.0;
    
        printf ("Enter a number (theta) to be calculated: ");
        scanf ("%lf", &theta);
        sin_theta = (tan (theta)) * (cos (theta));
        printf ("Tangent of theta times cosine of theta: %lf\n\n\n", 
                     sin_theta);
    
            return 0;
    }
    Any help is welcome. Thanks!

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    2,760
    What do you input to the program, and with this input what output does the program produce? What output do you expect? Also note that tan() is based on radians.

    Jim

  3. #3
    Registered User
    Join Date
    Sep 2012
    Posts
    2
    Oh, I see my problem! I was checking the math with WolframAlpha and it assumed the values I plugged in were degree values. Turns out my code works! Thanks for the reminder about the radians.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with functions...
    By yaya in forum C++ Programming
    Replies: 4
    Last Post: 12-27-2007, 01:25 AM
  2. problem with using functions
    By Drakon in forum C++ Programming
    Replies: 1
    Last Post: 03-28-2004, 07:09 PM
  3. Problem with functions
    By lizardking3 in forum C++ Programming
    Replies: 4
    Last Post: 09-22-2003, 04:34 PM
  4. Replies: 6
    Last Post: 05-06-2003, 03:08 PM
  5. Problem with two set of functions..
    By zahid in forum C Programming
    Replies: 7
    Last Post: 12-04-2002, 07:54 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21