1. ## help with functions!

have created a code for solving time capacitor takes to charge up at certain percentages but have run into difficulties.

1.answers i get for time seem to be off ( have worked out examples on paper mathemtically to test this ) wondering if anyone can see where ive gone wrong!

2. for extra marks would like to make use of functions in my code any help would be greatly appreciated. ( as far as i can tell there is only need for one function with three variables in but ive been wrong before)

Code:
```#include <math.h>#include <stdio.h>
void main()
{
float r;//declaration of resistance variable
float c;//declaration of capacitor varablle
float pv;//declaration of percentage variable as a raio of 100%=1.0
float t;// declaration of the time variable

printf("please enter the value of the resistor in the circuit\n");
scanf("%f",&r);
printf("please now input the value of the capacitor in the circuit\n");
scanf("%f", &c);
printf("please now enter the percentage value you would like to investigate as a ratio of 0-1 ( 100%=1.0 )\n");
scanf("%f", &pv);

t=-r*c*log(1-pv);
printf(" the amount of time passed for this given percentage is %f",t);

getch();
}```

2. Ok... first thing... only post plain text in code tags. The forum highlights it for you.

You might want to change your floats to doubles for added precision. But do keep in mind that floating point math on PCs is an approximation at best. (Not every decimal value can be accurately represented in the binary storage used by computers)

For the bonus points you could make the calculation into a function... It's about your only real candidate.

Also I don't know if it's a copy-paste error or if it's a problem in your code, but you can't put two preprosessor commands on the same line.

Finally... void main() is wrong... Windows and Linux (and probably Mac too) expect a return value from programs they run. The correct program skeleton is...
Code:
```int main (void)
{

return 0;
}```

3. okay thanks, so how do i go about putting the calculation into a function? ( sorry if its a pretty basic question )

4. Ok... widen your field of view just a little...

What is main() ... it's a function, yes?
You know how that works.
So you're already half way there.

Fix the current problems, get it working *at all* then give it your best shot.
Post your code if it gives you trouble...