Hello cprogramming.com, I am currently taking my first c programming course as a requirement for my mechanical engineering degree, so please bare with me if i am so oblivious. I am having the hardest time figuring out why i keep getting this parse error.
prompt:
Write a function that accepts two arguments, integer n and real number x, computes the following series, and returns the computed result:
1 – 2(x^2)/1! + 3(x^4)/2! – 4(x^6)/3! + … + [(-1)^n](n+1)(x^2n)/n!
The general term is:
negative one to the power of n
multiply by (n plus one)
multiply by x to the power of (2n)
divided by n factorial
Then write a C program that request two input from the user:
-- an integer number, n
-- a real number, x;
call the function passing those two input as arguments,
output the result returned by the function.
OK, so this is as far as i got. Everything LOOKS right.. but am i missing something so obvious??
Code:
#include<stdlib.h>
#include<stdio.h>
int main()
{
int x, n;
printf("Enter a value for n.\n");
scanf("%d", &n);
printf("n = %d\n", n);
printf("Enter a value for x.\n");
scanf("%d", &x);
printf("x = %d\n", x);
printf("Result = %d\n", compute(int x , int n));
system("pause");
return 0;
}
int compute(int x, int n)
{
int i, term, xsq, res;
i = 1;
xsq = x*x;
term = -1;
while(i<=n)
{
term = term*(-1)*xsq/i;
i = i+1;
}
res=term*(n+1);
return res;
}
now when i compile it tells me i have a parse error before ',' in the line that i bolded. can anyone please tell me where i went wrong? Thanks in advance