Hello guys I have been staring at this code for an hour and cant get it to work. My for loop on the bottom is not working. For some reason the array values keep resetting (value[row][col1]. This supposed to be Gauss-Seidel method so basically its an iterative method that relies on updated array values. Please help!
#include <iostream>
using namespace std;
int main()
{
int row,col,i,col1;
float array[3][4];
float value[3][4];
float x;
x = 1;
i = 0;
//Set values for the matrix and output into DOS display
for(row=0;row<3;row++)
{
for(col=0;col<4; col++)
{array[row][col]=x;
if(i<3)
{cout<< array[row][col]<< " ";
x=x*1.5+2;
i++;}
else{cout<<array[row][col]<<endl;
cout<<endl;
i = 0;
}
}
}
cout << endl;
cout << endl;
//resetting parameters
i = 0;
col1 = 0;
//assign values for matrix
for(row=0;row<3;row++)
{
for(col=0;col<4; col++)
{
if(i<3)
{
value[row][col1] = 0;
i++;
cout << value[row][col1]<< " ";
col1++;
}
else{
cout << array[row][col] <<endl;
i = 0;
col1 = 0;
}
}
}
// determine value of elements
for(i=0;i<2;i++)
{row = 0;
col = 3;
col1 = 0;
value[row][col1] = (array[row][col]-value[row][col1+1]*array[row][col1+1]-value[row][col1+2]*array[row][col1+2])/array[row][col1];
row++;
col1++;
value[row][col1] = (array[row][col]-value[row][col1-1]*array[row][col1-1]-value[row][col1+1]*array[row][col1+1])/array[row][col1];
row++;
col1++;
value[row][col1] = (array[row][col]-value[row][col1-1]*array[row][col1-1]-value[row][col1-2]*array[row][col1-2])/array[row][col1];
}
cout<< endl;
cout<< endl;
cout<< value[0][0]<<endl;
cout<< value[1][1]<<endl;
cout<< value[2][2]<<endl;
cin.get();
}