Ok, I need some help. I have done some research on this and nothing has helped. I'm new to this, taking a c programming class. Here is the problem given and what code I have and the errors.
(Algebra: solving linear equations) You can use Cramer’s rule to solve the following 2 x 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."
Test your program by calculating x and y for a = 9.0, b = 4.0, c = 3, d = -5, e = -6, and f = - 21.
/* File name is algebra.cpp
This program will solve a system of equations if the vaule is greater than zero.
Written
*/
#include <iostream>
using namespace std;
int main()
{
double a,b,c,d,e,f;
double x,y;
cout << "Please enter the value of a : " << a;
cout << "\nPlease enter the value of b : " << b;
cout << "\nPlease enter the value of c : " << c;
cout << "\nPlease enter the value of d : " << d;
cout << "\nPlease enter the value of e : " << e;
cout << "\nPlease enter the value of f : " << f;
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);
if (a*d - b*c= 0)
{
cout << "The equation has no solution.";
}
return 0;
}
3 errors:
line 23, 24, 29. "error C2106: '=' : left operand must be l-value
"unitialized local variable" means what it says. You're never setting x or y to anything. They're uninitialized.
What you're doing is similar to this:
1 2 3 4
int a = 1; // setting a to 1
int b; // if you don't set b to anything...
int c = a + b; // then what do you expect this result to be?
How can you expect the computer to add a and b together if you never told it what b is? What will the result of that addition be?
You have this problem with x and y in your code. Your program never sets x or y to anything, then it tries to multiply other numbers by x or y. What exactly do you expect the computer to be multiplying with?