Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to code this northwest method
    primarykey
    data
    text
    <p>I'm a student trying to learn about programming and have never done any complex coding before. Recently my lecturer gave me a task on Northwest corner method. I followed a code found on the internet but there seems to be some problems with this code which I cannot figure out as I'm still a beginner. I did some readings but I still couldn't figure out what the problems are and am quite sure there are many problems lies with the coding. I'm really thankful to those who are willing to take a look on the coding. Thanks in advance. :)</p> <pre><code>#include "stdafx.h" int _tmain(int argc, _TCHAR* argv[]) { return 0; } using namespace std; #include &lt;iostream&gt; #include &lt;fstream&gt; const int row_max =4; const int col_max =4; int i,j; //create supply_array and require_array float supply_array[row_max]; float require_array[col_max]; //creating the cost matrix and unit matrix float cost_matrix[row_max][col_max]; float unit_matrix[row_max][col_max]; //initialize cost_matrix int main() { for(i=0 ; i&lt;=row_max ; i++) { for(j=0 ; j&lt;=col_max ; j++) { cin &gt;&gt; cost_matrix[i][j]; } } //initialize unit_matrix for(i=0 ; i&lt;=row_max ; i++) { for(j=0 ; j&lt;=col_max; j++) { unit_matrix[i][j]=0; } } float cost_minimal= 0.0; float *supply_ptr; float *require_ptr; supply_ptr = &amp;supply_array[4]; require_ptr = &amp;require_array[4]; //initialize supply_array for(i=0 ; i&lt;=row_max ; i++) { cin &gt;&gt; supply_array[i]; } //initialize require_array for(i=0 ; i&lt;=col_max; i++) { cin&gt;&gt;require_array[i]; } float *matrix_ptr; matrix_ptr = &amp;cost_matrix[0][0]; int r=0,c=0,x=0,y=0; while((x&lt;= row_max) &amp;&amp;( y=col_max)) { if(*require_ptr&gt;*supply_ptr) { unit_matrix[x][y]=supply_array[x]; require_array[y]=require_array[y]-unit_matrix[x][y]; supply_array[x]=supply_array[x]-unit_matrix[x][y]; cost_minimal=cost_minimal+unit_matrix[x][y]; x=x+1; supply_ptr=supply_ptr+1; matrix_ptr=matrix_ptr+col_max; continue; } if(*require_ptr&lt;*supply_ptr) { unit_matrix[x][y]=require_array[y]; require_array[y]=require_array[y]-unit_matrix[x][y]; supply_array[x]=supply_array[x]-unit_matrix[x][y]*cost_matrix[x][y]; y=y+1; x=x+1; require_ptr=require_ptr+1; supply_ptr=supply_ptr+1; matrix_ptr=matrix_ptr+col_max; continue; } } //displaying the unit matrix for(i=0;i&lt;=row_max;i++) { for(j=0;j&lt;=col_max;j++) { cout&lt;&lt;unit_matrix[i][j]; } } //displaying the minimal cost cout&lt;&lt; "the minimal cost obtained is : "&lt;&lt;cost_minimal; return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload