# Just started c++ need help...(those who know basic matrices)

• 12-04-2007
Bloodasp92
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```
• 12-04-2007
Elysia
Code:

```    double a;     double b;     double c;     double a1;     double b1;     double c1;     double x = (1 / ((a * b1) - (b * a1)));```
a, b, c, a1, b1 and c1 does not have any values, because they're not initialized!
Therefore, your x variable will contain junk. It's not surprising you get junk results.
• 12-04-2007
Bloodasp92
What do u mean not initialized? Do i have to put double a = 0.00; ?? cuz i tried that and i get teh same junk results
• 12-04-2007
Elysia
It means they can contain any values from the given range of doubles.
It also seems to me that you are performing a calculation on x in the wrong part of the program. Those variables do not have a value yet and adding 0 to them will make you get division by 0, which is illegal.