I've looked into all the other threads and I am still lost.

``````#include<iostream>
#include<cmath>

using namespace std;

//Prototype's
//////////////////////////////
double functiony(double);
double area(int, double, double);

// Main
//////////////////////////////
int main (void)
{
//Solving for y=x^3 using k as y and d as x
double k;
double d=0;
k = functiony(d);

//Intergration
double sum;
sum = area (60, 1,8);
cout<<sum<<endl;

return(0);
}

// Function definitions
//////////////////////////////

//Calling y which I call k and d is x;
void functiony()
{     double k;
k=d*d*d;
return(k);
}

}

//Intergration f is number of rectangles, g is x1 and h is x2, d is x.
double area(int f, double g, double h)
{	double sum, step, d, k, area;
step = (g-h)/f;
sum=0;
d=0;
for (int i=1;i<=f;i++)
{	area=k*step;
sum=sum+area;
d=d+step;	}
return(sum);
}``````

my integration function works when I give k a value inside the function, I need to create k as a separate function, which I did, I'm just lost on where I can put it so the program will bring it into my integration function

First, your function definitions must always match your prototypes exactly. This means that you should have this definition of the functiony() function:

``````//Calling y which I call k and d is x;
double functiony(double d)
{
return d*d*d;
}``````

Then, if you need to use the functiony() function in your integration function, then you should simply do so, you need to call the functiony function within your integration function to compute k. Also, on a side note, to make the code clearer and safer, you should declare variables where you use them first, not all at the beginning of the function. So, your integration function could be like this:

``````//Intergration f is number of rectangles, g is x1 and h is x2, d is x.
double area(int f, double g, double h)
{
double step = (g-h)/f;
double sum = 0;
double d = g; //the 'd' value should start at x1 (g)
for (int i=1;i<=f;i++)
{
double k = functiony(d); //call the functiony function to get 'k' at value 'd'.
double area = k * step;
sum += area;
d += step;
}
return sum;
}``````

That's it.

Be a part of the DaniWeb community

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