2 Matrices

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bpurificacion
    New Member
    • Mar 2008
    • 9

    2 Matrices

    Just wondering how I can do an input on 2 different buffers (P & Q). Here's what I've got so far.

    #include <iostream>
    using namespace std;

    const int SIZE = 3;
    int P[3][3];
    int Q[3][3];
    int row;
    int col;

    int main()
    {
    int P[3][3]
    {
    cout << "Enter " << SIZE << " rows of " << SIZE << " integers each:\n";
    for (row = 0; row < SIZE; row++)
    for (col = 0; col < SIZE; col++)
    cin >> P[row][col];

    cout << "Displaying:\n" ;
    for (row = 0; row < SIZE; row++)
    {
    for (col = 0; col < SIZE; col++)
    cout << P[row][col]<< " ";
    cout << endl;
    }
    }

    int Q[3][3]
    {
    cout << "Enter " << SIZE << " rows of " << SIZE << " integers each:\n";
    for (row = 0; row < SIZE; row++)
    for (col = 0; col < SIZE; col++)
    cin >> Q[row][col];

    cout << "Displaying:\n" ;
    for (row = 0; row < SIZE; row++)
    {
    for (col = 0; col < SIZE; col++)
    cout << Q[row][col]<< " ";
    cout << endl;
    }
    }

    return 0;
    }
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Originally posted by bpurificacion
    const int SIZE = 3;
    int P[3][3];
    int Q[3][3];
    int row;
    int col;
    These global variables should be local variables inside main().

    Then remove the int P[3][3] Q[3][3] in main().

    That should get your code to compile.

    Comment

    Working...