Thread: new to C, expected expression before 'double' message

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

    new to C, expected expression before 'double' message

    i need to 'Write a program to print a table of ex using both a function and the exp() function from the math.h library, for x = 0 to 1 in steps of 0.1. The program should ask the user what value of n to use, being how many terms in the taylor expansion.' I get the error message 'expected expression before 'double' and dont know what to do!
    Code:
    #include <stdlib.h>
    Code:
    #include <stdio.h>
    #include <math.h>
    
    
        
        double taylor(double x, int n) 
        {
            int i; 
            double sum = 1.0; 
            double term = 1.0; 
            for (i=1; i<=n; i++) 
            {
                term = term * x / i; 
                sum = sum + term;
            } return sum;
            
    }
    
    
    int main()
    
    
    {    
        int a, n;
        double b, c;
    printf("type in an int: ");
        scanf("%d", &n);
        
        for (a=0; a<=10; a++)
        {
            b = a/10.0;
            c = taylor(double b, int n);
        }
        
        printf("%f\t%f\n", b, c);
        
        exit(0);
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    When you pass a parameter to a function, you need not specify its type. Simply remove 'double' and 'int' where you are passing your variables (you still need them when declaring and defining functions though! just not calling them).

    Also, you should not terminate your program with exit(0). Your program will be terminated once control reaches the end of the main function. To return 0 from your main (the 0 in exit(0) is the return value) function simply add 'return 0' to the end.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2
    thank you so much! you can tell im pretty new to this, i was searching the internet for a while on what to do! im such a computing noob Much appreciated!

  4. #4
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    As long as you post brief code that demonstrates your problem clearly, explain what the program should do, and repeat any error messages that you get (all of these which you have already done) then everyone here will be happy to help you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. expected primary-expression before ']'
    By ooopa in forum C++ Programming
    Replies: 4
    Last Post: 11-14-2011, 09:35 AM
  2. Expected primary expression
    By MarlonDean in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2008, 03:43 PM
  3. expected primary expression
    By mju4t in forum C Programming
    Replies: 2
    Last Post: 03-27-2007, 06:59 PM
  4. Error: expected an expression!
    By bobthebullet990 in forum C Programming
    Replies: 2
    Last Post: 01-05-2007, 09:05 AM
  5. expected constant expression
    By Brian in forum C Programming
    Replies: 4
    Last Post: 12-03-2003, 03:30 PM