# Thread: Function and arguement help

1. ## Function and arguement help

I am new to C programming and having a hard time writing this program. If somebody can help it would great. This program ask the user for initial velocity and initial angle, then must calculate the max distance, max height and total travel time. The "requirements " must use at least 3 function not including the main function.
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int totaltraveltime(float velocity,float angle,float gravity);
int peakheight(float velocity,float angle,float gravity);
int range(float velocity,float angle,float gravity);

int main(void)
{
float initial_velocity=0;
float initial_angle=0;
float gravity=9.8;
float max_distance;
float max_height;
float duration;

scanf("%f",&initial_velocity);

scanf("%f",&initial_angle);

max_distance = range(initial_velocity,initial_angle,gravity);

max_height = peakheight(initial_velocity,initial_angle,gravity);

duration = totaltraveltime(initial_velocity,initial_angle,gravity);

system("PAUSE");
return 0;
}

int totaltraveltime(float velocity,float angle)
{
duration= 2*((initial_velocity)*sin(initial_angle))/gravity;

return duration;
}
int peakheight(float velocity,float angle,float gravity)
{
max_height=((initial_velocity)*sin(pow)(initial_angle))/(2*gravity);

return max_height;
}
int range(float velocity,float angle,float gravity)
{
max_distance=((pow)(initial_velocity)*sin(2*initial_angle))/gravity;

return max_distance;
}``` 2. So What's the problem?

Code:
```int totaltraveltime(float velocity,float angle,float gravity);

int totaltraveltime(float velocity,float angle)
{
duration= 2*((initial_velocity)*sin(initial_angle))/gravity;

return duration;
}``` 3. ## The text book assign to the class is Matlab.

The text book that is issued to the class is for Matlab. My teacher don't want us to use Matlab yet. So most information i get is over the internet Originally Posted by timbean I am new to C programming and having a hard time writing this program. If somebody can help it would great. This program ask the user for initial velocity and initial angle, then must calculate the max distance, max height and total travel time. The "requirements " must use at least 3 function not including the main function.
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int totaltraveltime(float velocity,float angle,float gravity);
int peakheight(float velocity,float angle,float gravity);
int range(float velocity,float angle,float gravity);

int main(void)
{
float initial_velocity=0;
float initial_angle=0;
float gravity=9.8;
float max_distance;
float max_height;
float duration;

scanf("%f",&initial_velocity);

scanf("%f",&initial_angle);

max_distance = range(initial_velocity,initial_angle,gravity);

max_height = peakheight(initial_velocity,initial_angle,gravity);

duration = totaltraveltime(initial_velocity,initial_angle,gravity);

system("PAUSE");
return 0;
}

int totaltraveltime(float velocity,float angle)
{
duration= 2*((initial_velocity)*sin(initial_angle))/gravity;

return duration;
}
int peakheight(float velocity,float angle,float gravity)
{
max_height=((initial_velocity)*sin(pow)(initial_angle))/(2*gravity);

return max_height;
}
int range(float velocity,float angle,float gravity)
{
max_distance=((pow)(initial_velocity)*sin(2*initial_angle))/gravity;

return max_distance;
}``` 4. Is that the way I need to define the prototype? I do not know what I am doing wrong =( 6. A function prototype looks like the function definition (except it doesn't have the braces with the function body). So, if you have a function that takes one int and returns one, its prototype might look like:
Code:
`int foo( int );`
Then the actual function may look something like:
Code:
```int foo( int x )
{
...do stuff with x
return someint;
}```
If you have a specific question, please ask as specific as you can. General questions get general answers. Specific questions are more likely to get specific answers.

Quzah. 7. ## Here is my problem

1. When i compile I get a error message on line 40. 'conflicting types for totaltraveltime'

2. I have my formula = to duration.

Code:
``` int totaltraveltime(float velocity,float angle)
{
duration= 2*((initial_velocity)*sin(initial_angle))/gravity;

return duration;
}```

Will the value i get go inside the "main function"?

Code:
` duration = totaltraveltime(initial_velocity,initial_angle,gravity);` 8. I have no idea where line 40 is, but at a rough guess:
Code:
`int totaltraveltime(float velocity,float angle,float gravity);`
Code:
`int totaltraveltime(float velocity,float angle)`
Do those look the same to you?

And that's what return does -- it returns that value to the caller. You don't have to use the same name if you don't want to, as the duration that's inside the function and the duration that's inside main aren't going to be related at all anyway. 9. Thank You very much. I did not see that. Popular pages Recent additions 