# why its not working?

• 11-01-2010
Dulus
why its not working?
hi
having an irritating problem. i've tried everything i know, still, cant figue why its not working..

the program should get from you a "n" value, and calculate the deniz function as clearly be seen...

Code:

```#include <stdio.h> #include <stdlib.h> #include <math.h> long deniz ( double x); int main(void) {   int i;   int n;   long total = 0;   printf (" n value ?? \n");     scanf ( "%d", &n );     for ( i = 1;i <= n; ++i )   {  total = total + deniz(i);   } printf( "output %f", total);   system("PAUSE");          return 0; } long deniz (double x) { return log(x)-x ; }```
• 11-01-2010
Prelude
>for ( i = 1; 1 <= i <= n; ++i )
That's not meaningful. I suspect you meant:
Code:

`for (i = 1; i <= n; ++i)`
• 11-01-2010
Dulus
ah. figures...

yep, thanks. i've corrected it. i dont know why i wrote that...

but still :S

when i run the program, says

"output 0.000000"
• 11-01-2010
Prelude
You're using %f to print a long integer. Try %ld instead, or change total to either float or double.
• 11-01-2010
jimblumberg
Check you format specifier for the following printf:

Code:

`printf( "output %f", total);`
Is total a double?

Jim
• 11-01-2010
Dulus
right...
very very thank you again.
i got to study a little more i guess...

gentleman,
i still got a problem.
the program still doesent give expected output.

for example, for n=3 output has to be -4,208240...

but it gives me -3...

• 11-01-2010
jimblumberg
You are mixing longs with doubles. Long like int will truncate the result to an int value.

You should change to using double and not long.

Jim
• 11-01-2010
CommonTater
One possibility... Your i variable is an integer but the deniz function is asking for a double.

You should use a typecast when calling the function...
Code:

`total = total + deniz((double) i);`
Also... please don't go back and edit your code. Leave the old one there and post a new copy so that others with the same problem can follow how you solved it.