hey guys!
so I need to create a matrix 6x6 and then fill it with random numbers from 0 to 3.... and I need to leave the diagonal of the matrix with 0s...

The rows are supposed to be soccer teams so if row 1 wins row 2... the program needs to print a 3... if it's a tie it's 1 and if row 1 loses it's 0... like that...
then I need to see which team makes more points and that is the one that wins....
so far I've created the matrix but I don't know how to print 0s in the diagonal or compare numbers that are in the matrix... please help!!!!

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

static const int conROWS = 6;
static const int conCOLS = conROWS;

int main(int argc, char* argv[])
{
double matrix[conROWS][conCOLS];

double maxvalue[conROWS];

double finalvalue;

int r,c;

srand(clock() + time( NULL )); //seed the random number generator

//fill matrix with random values in range 1..100
std::cout << "Matrix:" << std::endl;
for(r=0; r<conROWS; r++)
{
for(c=0; c<conCOLS; c++)
{
matrix[r][c] = (rand() % 4) ;
std::cout << matrix[r][c] << " ";
};
std::cout << std::endl;
};

//work out max row element
for(r=0; r<conROWS; r++)
{
maxvalue[r]= 0;
for(c=0; c<conCOLS; c++)
{
if(matrix[r][c] > maxvalue[r])
maxvalue[r] = matrix[r][c];
};
std::cout << " \nMax value in row " << r << " is " << maxvalue[r];
};

finalvalue = 0;
for(r=0; r<conROWS; r++)
{
if(maxvalue[r]>finalvalue)
finalvalue = maxvalue[r];
}

std::cout << " \nMax of row values is " << finalvalue << std::endl;

//todo workout max value overall and display it
system ("pause");
return 0;
};``````

TBH, I cant read your code.... You used code tags but no indentation..... people are MUCH more likely to help if your formatting is good.... or even readable

Getting 0s down the diagonal is simple.
After filling it, run a simple loop the size of the row or col dimension, using the loop counter as both row and column index, setting those elements to 0.

Or, when you allocate the array, initialize it to 0s (which one really should do in all cases), then in the loop where you fill it with random values test for row index == col index. If true, skip it, otherwise assign a value.

As to evaluation of all this, your explanation doesn't make a lot of sense. Do the row values indicate the score the team made in its games with the other teams (columns)? That is, matrix[0][5] is the score that the first mean made in its game with team 6, and team 6's score against team 1 is shown at matrix[5][0]?

Getting 0s down the diagonal is simple.
After filling it, run a simple loop the size of the row or col dimension, using the loop counter as both row and column index, setting those elements to 0.

Or, when you allocate the array, initialize it to 0s (which one really should do in all cases), then in the loop where you fill it with random values test for row index == col index. If true, skip it, otherwise assign a value.

As to evaluation of all this, your explanation doesn't make a lot of sense. Do the row values indicate the score the team made in its games with the other teams (columns)? That is, matrix[0][5] is the score that the first mean made in its game with team 6, and team 6's score against team 1 is shown at matrix[5][0]?

I'll try that for the diagonal...
for example, row 1 is team 1, row 2 is team 2, row 3 is team 3 and so on... row 1 plays with row 2; row 3 with row 4 and row 5 with row 6... I guess I have to use the 0s diagonal as well... and then at the end I need to write a cout that says team 1 has xx points, team 2 has xx points... the winner is team xx

ok, I already implemented the diagonal...
what's missing is the points part

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

using namespace std;

static const int conROWS = 6;
static const int conCOLS = conROWS;

int main(int argc, char* argv[])
{
double matrix[conROWS][conCOLS];

double maxvalue[conROWS];

double finalvalue;

int r,c;

srand(clock() + time( NULL )); //seed the random number generator

//fill matrix with random values in range 1..100
std::cout << "Matrix:" << std::endl;
for(r=0; r<conROWS; r++)
{
for(c=0; c<conCOLS; c++)
{
matrix[r][c] = (rand() % 4) ;

if (matrix[r]== matrix[c])
std::cout << "0 ";

std::cout << matrix[r][c] << " ";
};

std::cout << std::endl;
};

//work out max row element
for(r=0; r<conROWS; r++)
{
maxvalue[r]= 0;
for(c=0; c<conCOLS; c++)
{
if(matrix[r][c] > maxvalue[r])
maxvalue[r] = matrix[r][c];
};
std::cout << " \nMax value in row " << r << " is " << maxvalue[r];
};

finalvalue = 0;
for(r=0; r<conROWS; r++)
{
if(maxvalue[r]>finalvalue)
finalvalue = maxvalue[r];
}

std::cout << " \nMax of row values is " << finalvalue << std::endl;

//todo workout max value overall and display it
system ("pause");
return 0;
};``````