ok so ive been working on the code for weeks now for class and i dont know how to start inputing a function this is what i have

#include <iostream>
using namespace std;

int main()
{
//declare variable//

const double g = 9.8;
 double s =1;
double d;
cout<<"Seconds    "<< "    Distance" <<endl;
cout<<"========================" <<endl;

for(s=1; s <= 10; s++)

{

//equation for distance falling//
d = ((.5)* g * s * s);


cout << s << "           " << d << endl;
 


}

#pragma region wait
cout<<" Press Enter to Quit";
cin.ignore();
cin.get();
#pragma end region
return 0;
}

the code does what i want it to but how do i get the equation "d = ((.5)* g * s * s)" as the function?

One, make g a global constant (i.e. define it BEFORE, not INSIDE main). Then move your code outside of main and call it from main. You already have the formula:

d = ((.5)* g * s * s);

Make a function out of it:

double getDistance(double s)
{
    double d = ((.5)* g * s * s);
    return d;
}

Now call it from main:

d = getDistance(s);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.