not loading a dynamic array (128,8) correctly

This is a discussion on not loading a dynamic array (128,8) correctly within the C# Programming forums, part of the General Programming Boards category; Code: public void dam_data_setup() { // fill list damgtype.Add( den1); damgtype.Add( den2); damgtype.Add( da1); damgtype.Add( da2); damgtype.Add( db1); damgtype.Add( db2); ...

  1. #1
    Registered User
    Join Date
    Aug 2011
    Posts
    4

    not loading a dynamic array (128,8) correctly

    Code:
         public void dam_data_setup()
            {
                // fill list
                 damgtype.Add( den1);
                 damgtype.Add( den2);
                 damgtype.Add( da1);
                 damgtype.Add( da2);
                 damgtype.Add( db1);
                 damgtype.Add( db2);
                 damgtype.Add( dc1);
                 damgtype.Add( dc2);
                 damgtype.Add( dd1);
                 damgtype.Add( dd2);
                 damgtype.Add( de1);
                 damgtype.Add( de2);
                 damgtype.Add( dv1);
                 damgtype.Add( dv2);
    
                // convert list to array
                int[] dam =  damgtype.ToArray();
                int dx = 0; // dam data array pointer
                 den = 1;  da = 1;  db = 1;  dc = 1;  dd = 1;  de = 1;  dv = 1;  //sets array col position counters to starting values
                int broken_max =  rows, agouti_max = (broken_max / 2), brown_max = (agouti_max / 2), colour_max = (brown_max / 2), dilute_max = (colour_max / 2), ext_max = (dilute_max / 2), vienna_max = (ext_max / 2);
                int dam_dom_dilute = (dd / (dilute_max / 2));
                do
                {
                    // loading array right to left. starts by loading all itirations of broken starting with the Dominant gene (locii)
                    // when gene counter is > 1/2 gene max counter; recessive is loaded
                    {  //broken
                        if ( den <= (broken_max / 2))
                        {
                             damdata[dx, 0] = dam[0];
                        }
                        else
                        {
                             damdata[dx, 0] = dam[1];
                        }
                         den++;
                        if ( den > broken_max)
                        {  den = 1; }
                    }
                    {
                        // Agouti 
                        if ( da <= (agouti_max / 2))
                        {  damdata[dx, 1] = dam[2]; }
                        else if ( da > (agouti_max / 2)) {  damdata[dx, 1] = dam[3]; }
                         da++;
                        if ( da > agouti_max) {  da = 1; } // resets Agouti counter
                    }
                    {
                        // Brown
                        if ( db <= (brown_max / 2))
                        {  damdata[dx, 2] = dam[4]; }
                        else if ( db > (brown_max / 2)) {  damdata[dx, 2] = dam[5]; }
                         db++;
                        if ( db > brown_max) {  db = 1; } // resets Brown counter
                    }
                    {
                        // Colour
                        if ( dc <= (colour_max / 2))
                        {  damdata[dx, 3] = dam[6]; }
                        else if ( dc > (colour_max / 2)) {  damdata[dx, 3] = dam[7]; }
                         dc++;
                        if ( dc > colour_max) {  dc = 1; } // resets Colour counter
                    }
                    { // Dilute
                        if (dd > (dilute_max / 2))
                        { damdata[dx, 3] = dam[9]; }
                        else if (dd <= (dilute_max / 2)) { damdata[dx, 4] = dam[8]; }
                      sd++;
                        if ( dd > dilute_max) {  dd = 1; } // resets Dilute counter
                    }
                    {
                        // Extension
                        if ( de > (ext_max / 2))
                        {  damdata[dx, 5] = dam[11]; }
                        else if ( de <= (ext_max / 2)) {  damdata[dx, 5] = dam[10]; }
                         de++;
                        if ( de > ext_max) {  de = 1; } // resets Extension counter
                    }
    
                    {
                        // Vienna 
                        if ( dv > (vienna_max / 2))
                        {
                             damdata[dx, 6] = dam[13];
                        }
                        else if ( dv <= (vienna_max / 2))
                        {
                             damdata[dx, 6] = dam[12];
                        }
                         dv++;
                        if ( dv > vienna_max) {  dv = 1; } // resets vienna counter
                    }
                    dx++;
                } // end do bracket
                         while (dx < rows); // end do while loop
    
                return;
            }
    This is a genetics program and is to parse the source array and write all possible combinations to a new array.

    All sections but dilute work correctly. For some reason the dilute's Boolean is not testing true when it should. This is causing data corruption. What am I doing wrong?

  2. #2
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,139
    When you are writing C# you migh as well follow the C# coding guidelines especially concerning naming and spacing. Your code looks like a mess of badly formatted C.

    None of your variable names make sense to me (probably because I'm not into genetics) and half your variable types are hidden from view. I'm not going to play your debugger. Press F9 on the line you are having problems with. Then hit F5, wait for Visual Studio to jump to this line and compare the values. One won't be what you expected. Follow this mistake until you find your problem and fix it.
    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.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,821
    LOL - copy/paste for the win (or in your case, loss)
    Code:
                   {  damdata[dx, 1] = dam[2]; }
                   {  damdata[dx, 2] = dam[4]; }
                   {  damdata[dx, 3] = dam[6]; }
                   {  damdata[dx, 3] = dam[9]; }
                   {  damdata[dx, 5] = dam[11]; }
    Gotta laugh - you managed to change one of them to 4, but not the other.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  4. #4
    Registered User
    Join Date
    Aug 2011
    Posts
    4
    Quote Originally Posted by Salem View Post
    LOL - copy/paste for the win (or in your case, loss)
    Code:
                   {  damdata[dx, 1] = dam[2]; }
                   {  damdata[dx, 2] = dam[4]; }
                   {  damdata[dx, 3] = dam[6]; }
                   {  damdata[dx, 3] = dam[9]; }
                   {  damdata[dx, 5] = dam[11]; }
    Gotta laugh - you managed to change one of them to 4, but not the other.
    yeah and the other was sd++ which needed to be dd++.
    fixed those 2 things and that section of code is now working.

    Murphy's law: the simplest thing will be the hardest to see.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linking versus Dynamic Loading / MySQL
    By Dino in forum C Programming
    Replies: 5
    Last Post: 09-27-2009, 04:38 PM
  2. Loading data into a dynamic array
    By serge in forum C++ Programming
    Replies: 9
    Last Post: 06-18-2009, 04:36 PM
  3. Loading a file of words into dynamic char**
    By strakerc in forum C Programming
    Replies: 11
    Last Post: 07-11-2008, 08:20 PM
  4. Dynamic loading with C++
    By karas in forum Linux Programming
    Replies: 7
    Last Post: 12-25-2006, 02:13 AM
  5. Win32 API - Dynamic Link Library Loading - behind the scenes
    By Unregistered in forum Windows Programming
    Replies: 2
    Last Post: 04-05-2002, 08:31 AM

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