Hi.
Im making a program which uses an array from the main function and passes it to a function which displays a table.
However i am having a problem with calling the function in the main.
When i compile my program it shows error LNK2001 (unresolved external symbol).
Thanks for your help.

#include <iostream>								
#include <cmath>                                                                                            #include <iomanip>                                                                                        

using namespace std;											
void table(double, double);

int main()
{
	double q;

	cout << "Enter Q: ";
	cin >> q;
	
	const double PI = 4.0 * atan(1.0);

	double array1[61];                  
	int s;                              
	double i;						 
	double array2[61];					
	
	
	
	for (s = 0; s < 61; s++)
	{
		step = s *(PI)/30.0 ;    
		
array1[s] = 1.0/PI + (1.0/2) * sin(step) - 2.0/PI  *  (   (1.0/3) * cos(2 * step)       + (1.0/15) * cos(4 * step)      + (1.0/35) * cos(6 * step) );    
		array2[s] = array1[s] * q;
	}
	
	table(array1 [61], array2[61]);

	return 0;
}

void table( double array1[61],double array2[61])
{
	const double PI = 4.0 * atan(1.0);
	double var2;
	double var1;
	int k;
	

	cout << "DISPLAY \n";	
	cout << endl;

	for(k=0; k<=20; k++)
	{
		var2 = x *12;
		var1 = var2 * PI;
			
cout << "| " << var2 << "          " << var1  << "       " << array2[k] << " |" << endl;
	}

}

Edited 7 Years Ago by John A: added code tags

meanace,
Welcome to daniweb.

Following are some suggestions & corrections regarding to your post.
1.
Use bb code tags - It is a special tag to highlight the syntax of source code.
Take a look at - How to use BB code tag?
2.
ERROR : Signature of table function - Declaration and definition of function must use common set of arguments in same order and same datatype and their return type must be same.

Declaration of total function

void table(double [], double[]);

3.
Declaration of variable step in main() and x in total function is missing.

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

void table(double [], double[]);

int main()
{
    double q;

    cout << "Enter Q: ";
    cin >> q;

    const double PI = 4.0 * atan(1.0);

    double array1[61];
    int s;
    double i;
    double array2[61];

    for (s = 0; s < 61; s++)
    {
       double step = s *(PI)/30.0 ;

        array1[s] = 1.0/PI + (1.0/2) * sin(step) - 2.0/PI * ( (1.0/3) * cos(2 * step) + (1.0/15) * cos(4 * step) + (1.0/35) * cos(6 * step) );
        array2[s] = array1[s] * q;
    }

    table(array1,array2);

    return 0;
}

void table( double array1[],double array2[])
{
    const double PI = 4.0 * atan(1.0);
    double var2;
    double var1;
    int k;


    cout << "DISPLAY \n";
    cout << endl;

    for (k=0; k<=20; k++)
    {
        var2 = array1[k] *12;
        var1 = var2 * PI;

        cout << "| " << var2 << " " << var1 << " " << array2[k] << " |" << endl;
    }
}

Edited 7 Years Ago by __avd: n/a

Hi.
Thank you very much for your hepl with the array passing problem.
I just have one more query.
If i had three or more of the table functions, say one with k going from 20 to 40 and another from 40 to 60. How would i get the main to display the functions horizontally (all in a row) not vertically downwards?

This article has been dead for over six months. Start a new discussion instead.