I'm trying to compile the following code that I wrote out:
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
void gauss(double, double, double, int);
int main()
{
const int n1 = 4;
double prompt;
double A1[n1][n1] = {{3,0,3,-4},{0,1,1,1},{1,1,1,2},{2,3,1,3}};
double b1[n1] ={7,0,6,6};
double x1[n1];
gauss(A1, x1, b1, n1);
cout << x1;
cout << "\n Enter \'r\' to continue..." << endl;
cin >> prompt;
return 0;
}
void gauss(double A[][4], double x[], double b[], int n)
{
for(int k = 0; k < n; k++)
{
double divisor = A[k][k];
if(divisor == 0)
{
cout << "divisor is zero" << endl;
return;
}
else
for (int i = k + 1; i < n; i++)
{
double multiplier = A[i][k]/divisor;
for(int j = k + 1; j < n; j++)
A[i][j] = A[i][j] - multiplier * b[k];
}
}
if(A[n-1][n-1] == 0)
{
cout << "The last divisor is zero" << endl;
return;
}
for(int i = n - 1; i >= 0; i--)
{
x[i] = b[i];
for(int j = i + 1; j < n; j++)
x[i] = x[i] - A[i][j] * x[j];
x[i] = x[i]/A[i][i];
}
}
return;
}
When I do, the following errors come up (Not sure if they're interrelated):
16 cannot convert `double (*)[4]' to `double' for argument `1' to `void gauss(double, double, double, int)'
56 expected unqualified-id before "return"
56 expected `,' or `;' before "return"
and
57 expected declaration before '}' token
I'm wondering if perhaps it has something to do with the double data type or if maybe it's actually in the way that I'm passing the variables. I'm using Bloodshed Dev C++ as my compiler, if that helps.