Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing values in a 2D array
    primarykey
    data
    text
    <p>I have to create a program that allows a user to fill in a (partial) Latin Square of order 4. You can use 0's to represent empty cells. The user will give the number to place, the row and column. The number should only be placed if it does not violate the properties of a partial Latin square and it shouldn't rewrite numbers that have already been placed.</p> <p>I have an matrix that is outputting all zeroes now. So next I have to replace each of these values by what the user is inputting. The problem is I don't know how to do this.</p> <p>Here is my code:</p> <pre><code>#include &lt;iostream&gt; using namespace std; const int ORDER = 4; void fill (int m[], int order); void outputMatrix (int m[], int order); void replaceValue (int m[], int order, int n, int row, int column); int main(){ int matrix[ORDER]; int row; int column; int n; fill (matrix, ORDER); outputMatrix (matrix, ORDER); do { cout &lt;&lt; "Enter the number to place, the row and the column, each seperated by a space: "; cin &gt;&gt; n; cin &gt;&gt; row; cin &gt;&gt; column; }while (n &gt; 0 || n &lt;= ORDER); if (n &lt;= 0 || n &gt;= ORDER){ cout &lt;&lt; "Thank you"; cout &lt;&lt; endl; } return 0; } void fill (int m[], int order){ for (int i = 0; i &lt; order*order; i++){ m[i] = 0; } } void outputMatrix (int m[], int order){ int c = 0; for (int i = 0; i &lt; order*order; i++){ c++; cout &lt;&lt; m[i] &lt;&lt; ' '; if (c == order){ cout &lt;&lt; endl; c = 0; } } cout &lt;&lt; endl; } void replaceValue (int m[], int order, int n, int row, int column){ for (int i = 0; i &lt; order; i++){ m[order] = m[row][column]; m[row][column] = n; } } </code></pre> <p>How do I replace values in a Matrix in C++?</p>
    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.
    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