Doubt C ++ - basic solution Northwest corner

0

I'm a little forgetful of programming and I have a mathematical algorithm to do, it's the transport problem, I'm in the northwest corner phase.

My question is a compilation error.

Code:

#include<iostream>
#include<conio.h>
using namespace std;

int minimo(int valor1,int valor2)
{
    if(valor1<valor2)return valor1;
    else return valor2;
}


int main()
{
    int n,m,i,j;
    cin>>n>>m;
    int matriz[n][m];
    for(i=0;i<n-1;i++)for(j=0;j<m-1;j++)cin>>matriz[i][j];

    i=0;
    j=0;

    int x,y;
    x=n-1;
    y=m-1;

    while( ((i<=m-2)&&(i<=n-2)) && ((j<=m-2)&&(j<=n-2)) )
    do
{ matriz[i][j]=minimo(matriz[x,j],matriz[i,y]);
if(matriz[i][j]==matriz[x,j]){matriz[x,j]=0;matriz[i,y]-=matriz[i][j];}
if(matriz[i][j]==matriz[i,y]){matriz[i,y]=0;matriz[x,j]-=matriz[i][j];}

if(matriz[x,j]==0)i++;
 if(matriz[i,y]==0)j++;}

    return 0;
}

The error is this:

C:\Users\acer\Desktop\transporte.cpp||In function 'int main()':|
C:\Users\acer\Desktop\transporte.cpp|28|error: invalid conversion from 'int (*)[(((sizetype)(((ssizetype)m) + -1)) + 1)]' to 'int' [-fpermissive]|
C:\Users\acer\Desktop\transporte.cpp|5|error:   initializing argument 1 of 'int minimo(int, int)' [-fpermissive]|
C:\Users\acer\Desktop\transporte.cpp|28|error: invalid conversion from 'int (*)[(((sizetype)(((ssizetype)m) + -1)) + 1)]' to 'int' [-fpermissive]|
C:\Users\acer\Desktop\transporte.cpp|5|error:   initializing argument 2 of 'int minimo(int, int)' [-fpermissive]|
C:\Users\acer\Desktop\transporte.cpp|29|error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
C:\Users\acer\Desktop\transporte.cpp|29|error: incompatible types in assignment of 'int' to 'int [(((sizetype)(((ssizetype)m) + -1)) + 1)]'|
C:\Users\acer\Desktop\transporte.cpp|29|error: incompatible types in assignment of 'int' to 'int [(((sizetype)(((ssizetype)m) + -1)) + 1)]'|
C:\Users\acer\Desktop\transporte.cpp|30|error: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
C:\Users\acer\Desktop\transporte.cpp|30|error: incompatible types in assignment of 'int' to 'int [(((sizetype)(((ssizetype)m) + -1)) + 1)]'|
C:\Users\acer\Desktop\transporte.cpp|30|error: incompatible types in assignment of 'int' to 'int [(((sizetype)(((ssizetype)m) + -1)) + 1)]'|
C:\Users\acer\Desktop\transporte.cpp|39|error: expected 'while' before numeric constant|
C:\Users\acer\Desktop\transporte.cpp|39|error: expected '(' before numeric constant|
C:\Users\acer\Desktop\transporte.cpp|39|error: expected ')' before ';' token|
||=== Build failed: 13 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
    
asked by anonymous 12.01.2017 / 01:40

1 answer

0

You are incorrectly referencing array indexes in some parts of the code. matriz[x,j] for example. The correct one is matriz[x][j]

Another thing. There is no while (condição) do {} . The correct one is while (condição) { } or do {} while (condição) . Given this error, and the previous error, I would venture to say that you are migrating from Pascal to C.

I made the repairs to the syntax of your code, but I did not check the functionality, because I do not even know what it should do.

#include<iostream>
#include<conio.h>
using namespace std;

int minimo(int valor1,int valor2)
{
    if(valor1<valor2)return valor1;
    else return valor2;
}


int main()
{
    int n,m,i,j;
    cin>>n>>m;
    int matriz[n][m];
    for(i=0;i<n-1;i++)for(j=0;j<m-1;j++)cin>>matriz[i][j];

    i=0;
    j=0;

    int x,y;
    x=n-1;
    y=m-1;

    while( ((i<=m-2)&&(i<=n-2)) && ((j<=m-2)&&(j<=n-2)) ) 
    {
       matriz[i][j]=minimo(matriz[x][j],matriz[i][y]);

        if(matriz[i][j]==matriz[x][j]){
            matriz[x][j]=0;matriz[i][y]-=matriz[i][j];
        }

        if(matriz[i][j]==matriz[i][y]){
            matriz[i][y]=0;matriz[x][j]-=matriz[i][j];
        }

        if(matriz[x][j]==0)
        i++;
        if(matriz[i][y]==0)
        j++;

    }
   return 0;
}

I also recommend that you indent the code, as this will make it easier for anyone to help you.

    
12.01.2017 / 06:39