Am I missing something?

This is a discussion on Am I missing something? within the C Programming forums, part of the General Programming Boards category; I want to print a trigonometric table for sin, cos, and tan. Code: #include<stdio.h> #include<math.h> /* * Main Function */ ...

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    18

    Question Am I missing something?

    I want to print a trigonometric table for sin, cos, and tan.

    Code:
    #include<stdio.h>
    #include<math.h>
    /*
    *       Main Function
    */
    
    int main(void)
    {
            double two_pi = 2.0 * M_PI;
            double interval = two_pi / 19;
            double number;
    
            printf("Number, sin(), cos(), tan()");
    
            {
                    ("%lf%lf%lf%lf/n",number, sin(number), cos(number), tan(number));
                    for(number=0;number <= two_pi;number +=interval);
            }
    return 0;
    }

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    Uh, yeah. What the hell is this?
    Code:
    printf("Number, sin(), cos(), tan()");
    {
        ("%lf%lf%lf%lf/n",number, sin(number), cos(number), tan(number));
        for(number=0;number <= two_pi;number +=interval);
    }
    Or is that a REALLY bad copy/paste fail?
    Last edited by rags_to_riches; 10-11-2009 at 09:17 PM. Reason: Typo

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    18

    update

    Sorry this is the one that was on the actual program. I just typed that from my notebook while I was waiting for the program to run. It isn't much different. I just need it to do the increments....
    Code:
    #include<stdio.h>
    #include<math.h>
    int main(void)
    {
            double two_pi = 2.0 * M_PI;
            double interval = two_pi / 19;
            double number;
    
            printf("\nNumber        Sin( )        Cos( )        Tan( )        \n");
            scanf("%lf        %lf        %lf        %lf\n", &number, &sin(number), &cos(number), &tan(number));
            {
            for(number=0;number <= two_pi;number +=interval);
            }
    return 0;
    }
    Last edited by ke121885; 10-11-2009 at 08:52 PM.

  4. #4
    Registered User
    Join Date
    Sep 2008
    Posts
    58
    That is still bad. The opening brace before the for loop should be after.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    18
    so I have gotten this far...now with the incrementing? is there a tutorial that I can use?

    Code:
    int main(void)
    {
            double two_pi = 2.0 * M_PI;
            double interval = two_pi / 19;
            double number;
    
            printf("\nNumber        Sin( )        Cos( )        Tan( )        \n");
    
            for(number=0;number <= two_pi;number +=interval);
            {
            printf("%lf        %lf        %lf        %lf\n",number, sin(number), cos(number), tan(number));
            }
    return 0;
    }

  6. #6
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,650
    No semicolon at the end here:
    Code:
    for(number=0;number <= two_pi;number +=interval);
    Also, comparing doubles is fraught with danger, due to the imprecision of floating point mathematics.
    Last edited by rags_to_riches; 10-11-2009 at 09:19 PM. Reason: Additional info

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    18

    Smile hmmm...

    Now why did that semicolon stop my entire table from printing? (it worked by the way! Thanks)

  8. #8
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    A for statement is ended by the semi-colon. An early one just short-circuits all the printing code.

  9. #9
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Code:
    #include<stdio.h>
    #include<math.h>
    /*
     *       Main Function
     */
    
    
    int main(void)
    {
      double two_pi = 2.0 * M_PI;
      double interval = two_pi / 19;
      double number;
    
      for (number = 0; number < two_pi; number += interval)
        printf("%lf  || %lf  || %lf%  || %lf\n",number, sin(number), cos(number), tan(number));
    
      return 0;
    }
    there were quite some problems in the code like

    for statement was not correct syntax is
    for( intialize ; condition ; inc/dec) {}

    printf(); was not there and even syntax was not correct new line character is like this \n not /n this way

    you can not put like this printf() {
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  3. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 02:49 PM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 03:49 AM

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