# Write a function that computes e^x

Page 1 of 1

## 3 Replies - 359 Views - Last Post: 17 March 2011 - 03:55 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=222747&amp;s=22512bc15aca3d891e849971779d711d&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 MrJabbaNoHere

Reputation: 1
• Posts: 29
• Joined: 08-March 11

# Write a function that computes e^x

Posted 17 March 2011 - 03:50 PM

Hello everyone. I have written this simple code for an exercise in class. I understand all the logic, but why is it giving me these errors?

"Exercise1.c", line 19: syntax error before or at: ;
"Exercise1.c", line 25: syntax error before or at: return
"Exercise1.c", line 25: warning: old-style declaration or incorrect type for: sum

code is here
```#include <stdio.h>
#define EPSILON 0.000001;
float exp(float x);

int main(void)
{
float x;
printf("enter x: ");
scanf("%f" ,&x);
printf("%f",exp(x));
}

float exp(float x)
{
int n=1;
float term=1.0;
float sum=0.0;

while(term<EPSILON)
{
sum=sum+term;
term=term*x/n;
n++;
}
return sum;
}
```

Thanks.

Is This A Good Question/Topic? 1

## Replies To: Write a function that computes e^x

### #2 ishkabible

• spelling expret

Reputation: 1669
• Posts: 5,817
• Joined: 03-August 09

## Re: Write a function that computes e^x

Posted 17 March 2011 - 03:53 PM

you have a semicolon in your define directive for epsilon.
```#define EPSILON 0.000001;//<-write here, that should not be there
```

• Saucy!

Reputation: 6207
• Posts: 23,953
• Joined: 23-August 08

## Re: Write a function that computes e^x

Posted 17 March 2011 - 03:54 PM

Lose the ; here:

```#define EPSILON 0.000001;
```

what happens is when the preprocessor replaces EPSILON with 0.000001, you end up with this:

```while(term<0.000001;)
```

which is, of course, invalid.

### #4 MrJabbaNoHere

Reputation: 1
• Posts: 29
• Joined: 08-March 11

## Re: Write a function that computes e^x

Posted 17 March 2011 - 03:55 PM

It's always something simple! Thanks guys.