hi there people
i got a prob with my code
in my problem i got a matrix and i need to find the even number or numbers on that matrix (12x30) (by the way is the even minimun or minimums), so here is my function "tempeven" part., the actual issue is that is printing the 3 minimun even numbers, and sometimes is not printing anything.

void Tempeven(int X[][col])
{
    int cont=0;
    cout<<"the temperaturas even min: "<<endl;
    int min=X[0][0];
    for (int i=0;i<row;i++)
    {
        for (int j=0;j<col;j++)
        {

            if (X[i][j]%2 == 0 && X[i][j]<min)

                min=X[i][j];
                cout<<endl<<min;


        }
   }

}

If you move the ouptut statement outside of the for loops, then you should always print out the lowest value in the matrix.

If you want to out put the three lowest even values in the matrix then there are a variety of options. One approach would be to sort the matrix, then output the first three even numbers.

Member Avatar for atulgupta9

Just shift the output statement to the end of the outer for loop if you want to display the minimum even no. of each row

void Tempeven(int X[][col])
{
    int cont=0;
    cout<<"the temperaturas even min: "<<endl;
    int min=X[0][0];
    for (int i=0;i<row;i++)
    {
        for (int j=0;j<col;j++)
        {
            if (X[i][j]%2 == 0 && X[i][j]<min)
                min=X[i][j];

        }
   cout<<endl<<min; }
}

else you can also move the output statement to the end of both the for loops and then you will see the minimum even no. of the matrix

void Tempeven(int X[][col])
{
    int cont=0;
    cout<<"the temperaturas even min: "<<endl;
    int min=X[0][0];
    for (int i=0;i<row;i++)
    {
        for (int j=0;j<col;j++)
        {
            if (X[i][j]%2 == 0 && X[i][j]<min)
                min=X[i][j];

        }
  cout<<endl<<min; }
commented: thanks for the answer! thanks for your time +0

hi there guys
Thanks for replies, i still got some issues; the double for is working on every line of my matrix (as i said it was 12x30 matrix), and i need it to print just the number "the lowest even number" in the whole matrix, instead of printing the lowest in every line, thanks

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.