Thread: help...2 C++ problems

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    4

    help...2 C++ problems

    (I deleted the whole program because I don't want my school mates to copy it, anyway, sorry for the inconvenience)
    These two programs are the homework i needed to do. I had been figuring it out for two weeks. But my mind still seems to be stuck.

    The aim of this program is to solve a twoXtwo matrix (just a twoXtwo). I had successfully used another method to finish it before. But the homework requires me to bring in a inverseArray to save the values of the changed array

    PHP Code:
    void multiplyMatrices(double inverseArray[][2],double multArray[],double oneOverA)
    {
        
    multArray[0]=inverseArray[0][0]*inverseArray[2][0]+inverseArray[0][1]*inverseArray[2][1]*oneOverA;
        
    multArray[1]=inverseArray[1][0]*inverseArray[2][0]+inverseArray[1][1]*inverseArray[2][1]*oneOverA;

    I think the problem seems to be that inverseArray is changed after saving the array. But just don't know what to do with it.


    The techniques that are allowed are arrays and the stuff before that. I know I really suck in C++, please help me if anyone knows the solution. Thank you so much.
    Last edited by mr_god_god; 04-30-2006 at 05:41 AM.

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> if(chr!='y'||chr!='Y'||chr!='n'||chr!='N')
    Follow that logic and you will see that it always evaluates to true. If the character does not equal 'y', or if it doesn't equal 'Y', etc. Every character either doesn't equal 'y' or doesn't equal 'Y'. You are looking only for characters that don't equal 'y' and don't equal 'Y'.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    Thank you so much, I solved the second program.
    But how about the first one?

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    Code:
        double array[][2]={0};
        double inverseArray[][2]={0};
        double multArray[]={0};
    You need to set the size for these arrays when you declare them. I doubt that's the issue, but it should still be done. Also, why does your input loop have 3 values for i (0 to 2) where the rest of the code seems to assume only 2 values (0 and 1)?

  5. #5
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    Thank you so much again, you are right, I solved the program.

    For your question, the input loop prompts the user to enter values A,B,C,D,E,F:
    Code:
    cout<<"A(x1)+B(x2)=E"<<endl; 
    cout<<"C(x1)+D(x2)=F"<<endl<<endl;
    Sorry for the rest of your questions, I don't really understand what you mean. Can you rephrase it?

    And can you please tell me how come I have to do so?
    (p.s. My teacher taught me this would work)
    Last edited by mr_god_god; 04-30-2006 at 05:35 AM.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I'm not sure which of my questions you didn't understand, and now that the code is gone I don't remember exactly what I meant. Basically, you can specify a function parameter as double array[][2], but you can't specify the actual declaration of an array that way because there is no size for the first dimension. The function parameter works because the compiler doesn't care what the size is as an array parameter just points to an existing array. When you actually declare an array, though, the compiler needs the size so that it can create the memory for it. So I would use double array[2][2] or double array[3][2] depending on which one you actually wanted.

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    4
    I am sorry, but thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. No clue how to make a code to solve problems!
    By ctnzn in forum C Programming
    Replies: 8
    Last Post: 10-16-2008, 02:59 AM
  2. C Pointers Problems
    By mhelal in forum C Programming
    Replies: 8
    Last Post: 01-10-2007, 06:35 AM
  3. String Manipulation problems -_-
    By Astra in forum C Programming
    Replies: 5
    Last Post: 12-13-2006, 05:48 PM
  4. contest problems on my site
    By DavidP in forum Contests Board
    Replies: 4
    Last Post: 01-10-2004, 09:19 PM
  5. DJGPP problems
    By stormswift in forum C Programming
    Replies: 2
    Last Post: 02-26-2002, 04:35 PM