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

This is a discussion on Just started c++ need help...(those who know basic matrices) within the C++ Programming forums, part of the General Programming Boards category; Code: Hello all, Thank you all for taking some time to read and help. I have just started programming in ...

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    3

    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
    Last edited by Bloodasp92; 12-04-2007 at 07:24 AM.

  2. #2
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    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.

  3. #3
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    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

  4. #4
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,788
    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.
    Your app's structure is malformed. Rethink your design.

  5. #5
    Registered User
    Join Date
    Dec 2007
    Posts
    3
    you're a genius thanks. i just changed the double x = (1 / ((a * b1) - (b * a1))); to after
    cin>> c1;
    no idea how many thanks im giving you right now... THANKS THANKS THANKS..
    although this only solves the simplest of problems... its my first working self-made program T_T
    Last edited by Bloodasp92; 12-04-2007 at 03:53 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Started using C++ Without Fear to learn--novice questions!
    By AvocadoRivalry in forum C++ Programming
    Replies: 6
    Last Post: 10-20-2008, 03:48 PM
  2. help me!!
    By lilmiss in forum C Programming
    Replies: 6
    Last Post: 09-23-2008, 04:51 PM
  3. Replies: 10
    Last Post: 11-22-2007, 11:13 PM
  4. Newbie needing help with basic code!
    By TeZ258 in forum C++ Programming
    Replies: 4
    Last Post: 11-03-2007, 08:35 PM
  5. Help with a Basic C Program!!
    By KIwi_Fella in forum C Programming
    Replies: 10
    Last Post: 11-01-2002, 09:04 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21