Thread: trouble passing arguments to method

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    20

    trouble passing arguments to method

    Code:
     public static void linked_parent_setup()
            {
     // linked section 
    
    
                    { // check if valid pair
                            if ((jw.siredata[x, 2] == jw.sb1) && (jw.siredata[x, 3] == jw.sc2))
                            { cross_over_Sire(x); }
                            else
                                if ((jw.siredata[x, 2] == jw.sb2) && (jw.siredata[x, 3] == jw.sc1))
                                { cross_over_Sire(x); }
                    }
    
    return;
    }
    
      public static cross_over_Sire(int x)
            {
                if (random.NextDouble() <= 0.257)
                { return; } // if cross was successful returns
                else  // branches here
                {
                            if ((jw.siredata[x, 2] == jw.sb1) && (jw.siredata[x, 3] == jw.sc2)) // check which pair it is.
                            {  jw.siredata[x,3] = jw.sc1;} // changes to linked value
    
    
                            else 
                             
    
    
                                if ((jw.siredata[x, 2] == jw.sb2) && (jw.siredata[x, 3] == jw.sc1)) // check which pair it is.
                                { jw.siredata[x,2] = jw.sb1; } // changes to linked value.
                                 
                    }
    
    
        return();
        } // end cross_over_Sire()

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    Without knowing what the code is for, the only issue I see is you have an if statement that does the exact same thing when true or false.

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Your code is still formatted like a pile of garbage. Fix your formatting, I really don't know how to get it messed up like this in the first place. Visual Studio even does the formatting for you.

    I'll take a wild guess at your problem because you didn't tell what your problem is: you need to declare x in your function.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    The program is color genetics probability dealing with 2 linked locii (genes) that only crossover at a rate of 25.7%. I have 4 permutations to choose from of which 2 only occur 25.7% of the time.
    I do have x declared at the top of the method as an int.

    The if statement checks for 2 combinations and if true; should call another method to test if the crossover passed the 25.7% rate test.

    As in regards to the formatting; I am letting Visual Studio Express do the formatting. In what way is my formatting wrong?

  5. #5
    Registered User
    Join Date
    Jun 2003
    Posts
    129
    You can easily put both if condition statements in the same if. Surround both by brackets and use || as an or.

    Other than that I don't actually see what is going wrong. Do you get an error? Do you get a consistently wrong result?

    And how much of your homework are we going to have to help with?

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    Thanks to all for all the help. I have finished the program.

    This last problem was solved by haveing the ide create the method stub. I don't understand why that worked and the copy/paste did not.

    I am new to C# but not to programming. My programming background is COBOL. I asked for help here only after I'd googled and hit the books.
    It was the subtle nuances of C# that was giving me trouble.

  7. #7
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Quote Originally Posted by Dale View Post
    As in regards to the formatting; I am letting Visual Studio Express do the formatting. In what way is my formatting wrong?
    Code:
            public static void LinkedParentSetup(int x)
            {
                if (   ((jw.SireData[x, 2] == jw.sb1) && (jw.SireData[x, 3] == jw.sc2))
                    || ((jw.SireData[x, 2] == jw.sb2) && (jw.SireData[x, 3] == jw.sc1)))
                {
                    CrossOverSire(x);
                }
            }
     
            public static void CrossOverSire(int x)
            {
                if (random.NextDouble() > 0.257)
                {
                    if ((jw.SireData[x, 2] == jw.sb1) && (jw.SireData[x, 3] == jw.sc2))
                    {
                        jw.SireData[x, 3] = jw.sc1;
                    }
                    else if ((jw.SireData[x, 2] == jw.sb2) && (jw.SireData[x, 3] == jw.sc1))
                    {
                        jw.SireData[x, 2] = jw.sb1;
                    }
                }
            }
    This is what I would expect from a C# program. Apart from capitalization/underscores which really is a matter of taste, do you notice how I removed those comments because with good formatting, your code speaks for itself. No more "//end of function X" comments. Look at the vertical lines, it's blindingly obvious which function's end it is now
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  8. #8
    Registered User
    Join Date
    Nov 2011
    Posts
    20
    I see what your saying about formatting now. This was a case where my COBOL background was bleeding through . It was drilled into me to always comment everything.

  9. #9
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    It's not about commenting per se, commenting is good. But you were commenting your code because it wasn't formatted in a way that made your layout obvious. It's good to comment on what your program does. For example what all your two letter variables mean and what you intend to do with your program. If you feel the need to point out where your function ends because your braces are all over the place, it's a clear sign your formatting is nonexistent.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 11-28-2011, 06:25 PM
  2. Arguments return method is not working for float
    By girish1026 in forum C Programming
    Replies: 3
    Last Post: 09-23-2010, 01:26 AM
  3. having trouble with my freeArr() method
    By Dr Saucie in forum C Programming
    Replies: 3
    Last Post: 02-15-2010, 02:59 PM
  4. trouble with arguments in main method
    By vopo in forum C Programming
    Replies: 3
    Last Post: 07-15-2007, 10:14 PM
  5. passing arguments using "Command Line Arguments"
    By Madshan in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2006, 03:46 PM