# stupid problem. answer = 0.0

• 09-25-2004
spydrvnm
the code is pretty much a mess because i've been trying everything to figure this out on my own. every time i compile and test the program, no matter what values i put in i end up with 0.0 for the acceleration answer.

i needed at least 1 user defined function for the problem i'm doing or else it would all be in the main.

Code:

```#include <stdio.h> double calc_answer(double, double, double); /*User defined function*/ double show_answer(double); /*User defined function*/ int main(void) {         double vi=0, /*initial velocity input in meters per second*/         vf=0, /*final velocity input in meters per second*/         time=0, /*time input in seconds*/         accel1=0, /*acceleration calculation*/         accel=0; /*acceleration output in meters per second squared*/         printf("\n All values in seconds, meters per second, or meters per second squared");         printf("\n Please enter the initial velocity:"); /*input initial velocity*/         scanf("%lf", &vi);         printf("\n Please enter the final velocity:"); /*input final velocity*/         scanf("%lf", &vf);         printf("\n Please enter the time:"); /*input time*/         scanf("%f", &time);         calc_answer(vi, vf, time);         show_answer(accel);         return(vi, vf, time); } double calc_answer(double vi, double vf, double time) {         double accel1, /*acceleration part 1*/         accel; /*final acceleration calculation value*/         accel1 = vf-vi; /*Calculation of acceleration part 1*/         accel = accel1/time; /*final calculation of acceleration*/         return(accel); } double show_answer(double accel) {         printf("\n The acceleration is %.1lf \n\n\n\n", accel);         return; }```
any help will be greatly appreciated.
• 09-25-2004
ZeroG
Code:

```        scanf("%f", &time);         accel = calc_answer(vi, vf, time);         show_answer(accel);```
and i have no idea whats going on with the return statement.
• 09-25-2004
Hammer
Where are you trapping the return value from this function?

>>scanf("%f", &time);
Are you sure that's right?
• 09-25-2004
kermit

Code:

```void show_answer(double accel) {     printf("\n The acceleration is %.1lf \n\n\n\n", accel); }```
Just remember to change the function prototype to match.
• 09-25-2004
Hypercase
I dont think its really efficient to call a func to run just on line of code.
You display of the answer could be included in the calculation function.
• 09-25-2004
kermit
Depends on the situation. In this case it does not matter because it is a toy program. If the display was to be printed out many times, not dependent on the calculation, you would of course give it its own function. Something else to consider is that you ideally want your function to do one task, not many.
• 09-26-2004
spydrvnm
awesome! i got it. thanks alot guys.