mercredi 24 février 2016

Issue filling up and outputting a 3D array

I am trying to create a 3-Dimensional array which gets filled up with pseudo-random numbers ranging from 0 to 9 (inclusive). This is my first time working with arrays containing more than 2 dimensions, so I am a bit lost.

At first the only number being inputted into the array was a 1, but after changing some code around, every number but the last one is a 1, and the last digit is pseudo-random. To make matters worse with the new situation I am in, when I hit enter, I get a weird error message.weird error message

Besides these two errors (error filling up array, and debug error), I also cannot figure out how in the world to print it out in 3 groups of 3 x 3 numbers, although right now, that is a lower issue on my agenda (although hints for that would be appreciated).

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(){

    srand(time(NULL));


    const int arrayRow = 3, arrayColumns = 3, arrayDepth = 3;

    int fun[arrayRow][arrayColumns][arrayDepth];

    for (int r = 0; r < 4; r++){
        for (int c = 0; c < 4; c++){
            for (int d = 0; d < 4; d++){
                int value = rand() % 10;
                fun[r][c][d] = value;
                cout << fun[arrayRow][arrayColumns][arrayDepth];
            }
        }
    }
    cout << "Complete." << endl;
    system("pause");
}




Aucun commentaire:

Enregistrer un commentaire