linear equations problem

(algebra:solving linear equations) You can use Cramer's rule to solve the following 2*2 system of linear equation:

a*x+b*y=e
c*x+d*y=f

x=e*d-b*f/a*d-b*c
y=a*f-e*c/a*d-b*c

write a program that prompts the user to enter a, b, c, d, e, and f. and display the result. if ad-bc is 0, report that "The equation has no solution."

there was what i written

....dubugging...thx!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace std;
int main ()    
{
	double x;
    double y;
   	double a,b,c,d,e,f;
    cout << "Enter a, b, c, d, e, f: "; // Ask the user to enter the 6 numbers
    cin >> a >> b >> c >> d >> e >> f ; // enter the numbers
         
	if (a*d-b*c == 0)
	{
		cout << " The equation has no solution." << endl;
	}
    else
    { 
	    x = (e*d-b*f)/(a*d-b*c); 
        y = (a*f-e*c)/(a*d-b*c);
	   cout << " x is: " <<  x <<"and y is: " << y <<  endl;
    }
	return 0;
}
Last edited on
Ugh.

Must you use floating point?

The likelihood of your if statement being true is extremely small due to floating point roundoff error.
Are you sure you should manually be typing the values for e and f?
More complicated liner equations can be solved by Guass method.
For details please visit the website: http://hi.baidu.com/eryar/blog/item/138debc45c2560cf38db4983.html
Topic archived. No new replies allowed.