lundi 19 mars 2018

C++ Printing out 2D Array via a Function

So I'm trying to print out the values inside a 2D array, through a function called printArray, but everytime when i try it saysidentifier "print" is undefined.. I'm sure im doing something super super wrong, so any pointers would be greately appreciated :).

Also i'm trying to do it as simple as possible, no pointers or adresses ^^

#include "stdafx.h"
#include "iostream"

using namespace std;


int A[3][5];

class Matrix {
public:
Matrix() {
    A[0][1] = 5;
    A[1][2] = 3;
    A[2][1] = 2;
    A[3][4] = 10;   
}
void printArray(int height, int width);
};

int main()
{
print(A[3][5]);


return 0;
}

void Matrix::printArray(int width, int height) {
for (int i = 0; i < width ; i++) {
    for (int y = 0; y < height; y++) {
        cout << A[i][y] << " ";
    }
    cout << endl;
    }
}

Aucun commentaire:

Enregistrer un commentaire