NOTE: I had two variables with the same name... Big thanks to Stefan Birladeanu and Henrik for noticing that!*
Recently I started writing code that helps me input the values of bool function to Veitch (Karnaugh) diagram with 4 variables. The code should write elements to matrix size 4x4 but with these indexes:
element - index 1,1 This is the code of main():
void main()
{
int n;
n=4;
int **VeitchDiagram;
//allocate memory for Veitch diagram
VeitchDiagram = new int *[n];
for(int i=0; i<n; i++)
VeitchDiagram[i]=new int [n];
//enter the elements
for(int i=0; i<n; i++)
{
int j, k;
if(i%2==1)
{
k=0;
if(i<2)
j=4;
else
j=-1;
for(int k=0; k<2; k++)
{
if(i<2)
j--;
else
j++;
cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that):
k++; //0,3 1,3 0,2 1,2 if i%2==1 and i<2
cin >> VeitchDiagram[k][j]; //0,0 1,0 0,1 1,1 if i%2==1 and i>=2
k--;
}
}
else
{
k=3;
if(i<2)
j=4;
else
j=-1;
for(int k=0; k<2; k++)
{
if(i<2)
j--;
else
j++;
cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that):
k--; //3,3 2,3 3,2 2,2 if i%2==0 and i<2
cin >> VeitchDiagram[k][j]; //3,0 2,0 3,1 2,1 if i%2==0 and i>=2
k++;
}
}
}
//free memory allocated for VeitchDiagram
for(int i=0; i<n; i++)
delete [] VeitchDiagram[i];
delete [] VeitchDiagram;
}
for(int k=0; k<2; k++)
{
if(i<2)
j--;
else
j++;
cin >> VeitchDiagram[k][j]; //this part writes the input to elements with index (at least it should do that):
k--; //3,3 2,3 3,2 2,2 if i%2==0 and i<2
cin >> VeitchDiagram[k][j]; //3,0 2,0 3,1 2,1 if i%2==0 and i>=2
^ k == -1
But you really should learn how to use a debugger.