I have to write a program that takes a two dimensional array of dice and sees the combinations the dice makes within 360000 rolls. I have my code to work, but what I'm completely stumped with is printing it in a matrix. I know you have to embedd 2 for loops, but I don't know how else to go about it. what I need to do is something like is

                      Die 1
        1      2      3      4     5     6
   1

D  2

I  3

E  4                  Results

2  5

   6


   My code just prints the combinations going down as so

   result
   result
   result
   etc...

Here is my code:

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;

int main()
{
    const int die1 = 6;
    const int die2 = 6;
    int dice[die1][die2];
    int count = 0;

    while (count <= 360000)
    {
        dice[rand() % 6][rand() % 6]++;
        count++;
    }


    for (int i = 0; i < die1; i++)
    {
        for (int j = 0; j < die2; j++)
        {

            cout << dice[i][j] << endl;
        }


    }
}

Any help is truly appreciated. Mind you that I am in a beginner's class so no complicated programming...thank you!

You're adding endl after each result remove it from there and move to after the j loop. something like this:

for (int i = 0; i < die1; i++)
{
    for (int j = 0; j < die2; j++)
    {
        cout << dice[i][j] << "\t";
    }
    cout << endl;
}
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.