programing help

I am taking a online c++ programing class. Since its online i have no real instructer to help me understand the course. Our finals are due friday and one of the programing problems on it has got me stuck. I would really appreciate it if some one on here would be willing to help me by either giving me pointers in the right direction or making the program for me its not that its hard i just dont have the materials needed to help me figure it out.

heres the problem

Create a program which will generate a 5x5 matrix of random generated numbers using a muti dimensional array. Your values should range from 1 to 100. You will need to display the array to the screen, then the program will display the max value for each row and the max value for the array.

I can already get a array with randomly generated numbers but as for geting the max for each row and the max value i cant figure out. please im not trying to throw my work off on some one else this is just one of many problems on our final. thanks in advance.



Answer this question

programing help

  • Eric Eichler

    well i thought i had the array working but its not so basicly i have nothing done.


  • N_John

    I assume it is meant to be [ c ] - the posting tool is a bit eager to create emoticons - like Coffee

  • Denis Pitcher

    ok thanks for your help yea that was a step in the right direction but uh what are the coffee icons for


  • Davids Learning

    Paste the code youve written so far and we will see what we can sort out.

    Finding the max is really easy just iterate through each element in your row, something like this:
    int max = 0; //set to small value at first
    it (matrix[row][col] > max)//repeat for each column in the row
        max = matrix[row][col];




  • Martin Thwaites

    Something like this should get you started, please note i did not test this code.

    #include <cstdlib> //for rand() and srand()
    #include <ctime> //for clock() and time()
    #include <iostream> //for cin,cout,endl

    static const int conROWS = 5;
    static const int conCOLS = conROWS;

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

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

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


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

    //todo workout max value overall and display it
    return 0;
    };


  • AnnNeedsHelp

    alright i know you have already done alot for me but i ran your program this is what shows up

    0012FEA8 0012FEA8 0012FEA8 0012FEA8 0012FEA8
    0012FED0 0012FED0 0012FED0 0012FED0 0012FED0
    0012FEF8 0012FEF8 0012FEF8 0012FEF8 0012FEF8
    0012FF20 0012FF20 0012FF20 0012FF20 0012FF20
    0012FF48 0012FF48 0012FF48 0012FF48 0012FF48
    Max value in row 0 is 76Max value in row 1 is 91Max value in row 2 is 98Max valu
    e in row 3 is 91Max value in row 4 is 98Press any key to continue . . .

    why are the numbers showing up like that


  • JGMiller

    yep i keep forgetting to space out my brackets ie [ c ]

  • DanielN305517

    Im not sure why they are showing like that, its in hex, it shouldnt be.

    Can you paste the code you ran so i can check it


  • programing help