I need to do 2x2 array calculation.but not using global variable.

enterData()
calculate()
displayResult()

this are the three function. but i can't pass the value..
please help me..
I've done it without using function..

#include <iostream>
using namespace std;

calculate(int x[][],int y[][]);
enterData()
{
    int x[2][2];
    int y[2][2];
    int t[2][2];

    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
        cout<<"enter array num1"<<endl;
        cin>>x[i][j];
        cout<<endl;
        }
    }

    for(i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
        cout<<"enter array num2"<<endl;
        cin>>y[i][j];
        cout<<endl;
        }
    }

    calculate(x,y);
    return 0;
}
int calculate(x[][],y[][])
{
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
        t[i][j]=x[i][j]-y[i][j];


        }
        displayResult(t)
        cout<<endl;
    }
}

displayResult(int t)
{
    cout<<t<<endl;
}

a couple things I see, first of all, please see the link in my signature for the rules regarding code tags etc, it makes it MUCH easier for us to help you if we can see your code in a comprehensible manner. Second, I don't think this would compile, so if you get any compiler errors, please post those as that is going to point where 90% of the problem is coming from. Ok, here's your code with code tags:

#include <iostream>
using namespace std;

calculate(int x[][],int y[][]);

enterData()
{
    int x[2][2];
    int y[2][2];
    int t[2][2];

    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            cout<<"enter array num1"<<endl;
            cin>>x[i][j];
            cout<<endl;
        }
    }

    for(i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            cout<<"enter array num2"<<endl;
            cin>>y[i][j];
            cout<<endl;
        }
    }

    calculate(x,y);
    return 0;
}

int calculate(x[][],y[][])
{
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<2;j++)
        {
            t[i][j]=x[i][j]-y[i][j];
        }
        displayResult(t)
        cout<<endl;
    }
}

displayResult(int t)
{
    cout<<t<<endl;
}

problems I see: you have no main() function. I am assuming you were going for enterData() to act as that.

Second, you have to return type for your calculate function template or for your displayResult and enterData implementations.

what I mean by that is:

calculate(int x[][],int y[][]); //this
int calculate(int x[][],int y[][]); //should be this

displayResult(int t) //and this
{..}

void displayResult(int t) //should be this
{..}

enterData() //and this
{..}

int enterData() //should be this
{..}

and the last thing that I saw is that when you are passing a multidimensional array, you have to declare all the sizes of the array except for the first. for instance:

void functionName(int x[]); //this is ok
void functionName2(int x[][]); //not ok
void functionName3(int x[][2]); //ok
void functionName4(int x[][2][]); //not ok
void functionName5(int x[][2][2]); //ok
//etc.

if you wanted to avoid that, you could always just pass it as a double pointer since you know the size of the arrays will be 2. Hope that helps!

~J

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.