2 Replies - 21456 Views - Last Post: 03 March 2009 - 07:25 PM Rate Topic: -----

#1 thwhisler   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 20-February 09

error: cannot be used a function

Posted 03 March 2009 - 06:54 PM

I am writing a program that will calculate the determinates of 2 by 2 or 3 by 3 matrixes.
This is what i currently have:
#include <iostream>
#include <cstdlib>
using namespace std;


double det3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9);
double det2(double b1, double b2, double b3, double b4);

double a1, a2, a3, a4, a5, a6, a7, a8, a9;

int main()
{
int cType;
double det;

cout << "What is the size of the matrix? ";
cin >> cType;

cout << "\nEnter the terms going across\n";

  if (cType == 2)
	{
	  cin >> a1;
	  cin >> a2;
	  cin >> a3;
	  cin >> a4;
	  
	  det = det2(a1, a2, a3, a4);
	}

 else if (cType == 3)
	{
	  cin >> a1;
	  cin >> a2;
	  cin >> a3;
	  cin >> a4;
	  cin >> a5;
	  cin >> a6;
	  cin >> a7;
	  cin >> a8;
	  cin >> a9;

	  det = det3(a1, a2, a3, a4, a5, a6, a7, a8, a9);
	}
 else 
	{
	  cout << "Not a supported option.\n";
	 
	  exit(1);
	}

cout << "The determinant is " << det << endl;

return 0;
}


double det3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
  double det1, det2, det3, det5;

  det1 = (a1 * det2(a5, a6, a8, a9));
  det2 = (a4 * det2(a2, a3, a8, a9));
  det3 = (a7 * det2(a2, a3, a5, a6));

  det5 = det1 - det2 + det3;

  return det5;
}

double det2(double b1, double b2, double b3, double b4)
{
  double det4;

  det4 = (b1 * b4) - (b3 * b2);
  return det4;
}



When i compile it, I get the following errors:
determinant.cpp: In function ‘double det3(double, double, double, double, double, double, double, double, double)’:
determinant.cpp:62: error: ‘det2’ cannot be used as a function
determinant.cpp:63: error: ‘det2’ cannot be used as a function
determinant.cpp:64: error: ‘det2’ cannot be used as a function

What am I doing wrong?

Is This A Good Question/Topic? 1

Replies To: error: cannot be used a function

#2 polymath   User is offline

  • D.I.C Addict
  • member icon

Reputation: 53
  • View blog
  • Posts: 670
  • Joined: 04-April 08

Re: error: cannot be used a function

Posted 03 March 2009 - 07:21 PM

You cannot name your variables the same name as your function. Replace the det3 code with:
double det3(double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9)
{
  double d1, d2, d3, d5;

  d1 = (a1 * det2(a5, a6, a8, a9));
  d2 = (a4 * det2(a2, a3, a8, a9));
  d3 = (a7 * det2(a2, a3, a5, a6));

  d5 = d1 - d2 + d3;

  return det5;
}


Was This Post Helpful? 0
  • +
  • -

#3 thwhisler   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 11
  • Joined: 20-February 09

Re: error: cannot be used a function

Posted 03 March 2009 - 07:25 PM

Thank you! That worked perfectly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1