i need some help with a project of gravity for class and using it in a function here is what i currently have. But i cant seem to figure out how to make gravity a function within the loop and return the value distance
1. to make a function you must declare a return type (in this case double)
2. declare the name,
3. parenthetically declare the parameters, seperated by ,'s
4. do whatever you want to do in your function (int this case nothing)
5. return what you want to (return (gravity / 2) * time * time;)
1 2 3 4
function_return_type function_name (parameter_type parameter /*, continue pattern*/){
//do stuff with the function
return what_function_did;
}
then you can use a for loop to go from 0 seconds to (whatever your user input) seconds.
do something like this:
1 2 3 4 5 6 7 8 9 10
for (int temp = 0; temp <= USER_INPUT; temp++){
//The following lines up all numbers from 0 - 999
if (temp < 100){
cout << " ";
if (temp < 10){
cout << " ";
}
}
cout << temp << " seconds = " << distance_function(temp) << endl;
}