Just started c++ need help...(those who know basic matrices)
Code:
Hello all,
Thank you all for taking some time to read and help. I have just started programming in c++.
I tried to make a program to solve two simulataneous eqns for eg ( 3x + y = 7, x - 2y =0... What is x and y?)
I figured the only way to program this is to use the matrices method, which is finding the det and so on and so forth.
Here is the source code ( x is the determinant)
#include <iostream>
using namespace std;
int main()
{
double a;
double b;
double c;
double a1;
double b1;
double c1;
double x = (1 / ((a * b1) - (b * a1)));
cout<<"What is a? :";
cin>> a;
cout<<"What is b? :";
cin>> b;
cout<<"What is c? :";
cin>> c;
cout<<"What is a1? :";
cin>> a1;
cout<<"What is b1? :";
cin>> b1;
cout<<"What is c1 :";
cin>> c1;
cout<<"X = "<< (x * c * b1) + (x * c1 * -b);
cin.ignore();
cin.get();
return 0;
}
I tried it the forumula on paper and i can solve the problems fine but i cant seem to make it work..
i get answers like = -1.#IF or something like dat .. I really dont know what im doing wrong. So please help me out here Thanks alot
ps : this is supposed to find the value of X only(not the determinant)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~EDIT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For those of you who do not understand how this is supposed to work... here is an example
3x + y = 5
x - 2y = -3
therefore...
a=3(coeff of x first line)
b=1(coeff of y first line)
c= 5
a1=1(coeffe of x 2nd line)
b1= -2(coeff of y 2nd line)
c1 = -3