I want to test the code i wrote which is part of my assignment

double sine(double x, double tolerance, int & limit)
{
   int a = 1;
   double b = x;
   double z(0.0);
   do {
       b=(-z*x*x)/((2*a)*(2*a+1));
       z=b;
       z+=1;}
       while(fabs(b-z)>tolerance);
       limit= a;
       return b;
       }

im supposed to use a main() to test if the code works and im not sure how to do this
I would like a push in the right direction cause im stuck

Call the function in main(). Make sure to create 3 variables of appropriate data types to supply as parameters.

int main()
{
double var1, var2;
int var;
sine(var1, var2,  var);
return 0;
}//closes main

You'll need to give these variables values and then output the result of the function call.

I want to test the code i wrote which is part of my assignment

double sine(double x, double tolerance, int & limit)
{
       int a = 1;
       double b = x;
       double z(0.0);
       do {
           b=(-z*x*x)/((2*a)*(2*a+1));
           z=b;
           z+=1;}
           while(fabs(b-z)>tolerance);
           limit= a;
           return b;
           }

im supposed to use a main() to test if the code works and im not sure how to do this
I would like a push in the right direction cause im stuck

I dont know wat u want to accoplish in this function.. but if u are asking how to call this function in main() .. then here it goes...

int main()
{
double x;
double tolerance;
int limit;
sine(x,tolerance,limit); //parameters here are called actual parameters 
}

the parameters that u wrote while defining fuction are called formal parameters.. and when we call a functio.. Actual parameters are copied into fromal parameters...

Hope it helps..
njjoy!
-Snehil :)

yea thanks

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.