Where should i put my bool function?

Where should i include my bool isSolvable function so that it will be no error.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

void solveEquation(double,double,double,double,double,double,double &,double &, bool &);

bool isSolvable(double a, double b,double c,double d)
{
	if ((a*d)-(b*c) == 0)
	{return true;}
	else
	return true;
}

void solveEquation(double a, double b, double c, double d, double e, double f, double &x, double &y, bool &isSolvable)
{
x = (e*d - b* f)/(a*d - b*c);
y = (a*f - e* c)/(a*d-b*c);
}

int main ()
{	

	double a;
	double b;
	double c;
	double d;
	double e;
	double f;
	double x;
	double y;
	double g;
	bool isSolvable;
	cout << "Enter a, b, c, d, e, f: ";

	cin >> a;
	cin>>  b;
	cin >> c;
	cin >> d;
	cin >> e;
	cin >> f;
	solveEquation(a,b,c,d,e,f,x,y, isSolvable);
	
		cout << fixed << setprecision(1) << "x is " << x << " and y is " << y << endl;

	

}




a) Your function is bogus. Whatever happens, the result is "true". Most likely, the first "return true" should be "return false".

b) You're not calling your function. You're declaring a new bool variable with the same name, which is always a bad idea. Additionally, you're not initializing it.

c) There is no point for isSolvable (the argument in solveEquation) to be a reference. You can immediately pass the result of isSolvable (the function) to solveEquation by calling it this way:
solveEquation(a,b,c,d,e,f,x,y, isSolvable(a, b, c, d));
That can't be done as a reference (or at least shouldn't be).

Alternatively, you can first solve the result (in a bool variable with a differfent name, preferably) and then pass the variable:
bool isTotallySolvable = isSolvable(a, b, c, d); solveEquation(a,b,c,d,e,f,x,y, isTotallySolvable);
Now you can keep the parameter as a reference (still completely useless though).
http://imageshack.us/a/img341/555/questionx.jpg

the question asked me to make it a reference.
Then save the result in a variable, then pass the variable to the function.
The question did not tell you to make a function named isSolvable.
i know. but i dont know where and how should i define the bool inside the void.
On line 34 you are declaring a variable whose name is allready "reserved" :)
(ambigous simbol error)
function is called by typing it's name followed by brackets and arguments(if any).

Also I suppose your last argument in solveEquation function must not be a reference to local variable?

In case you don't understand local variables and function parameters I would recomment you to read Chapter 7 section 2 of Stroustrup's book which can be located here:
http://www.stroustrup.com/3rd.html
Topic archived. No new replies allowed.