Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: (C++) Never return the same integer in three "for" statements  (Read 6264 times)

0 Members and 1 Guest are viewing this topic.

liambiscuit

    Topic Starter


    Hopeful

    If i have this:

    Code: [Select]
    for ( int z = 1; z < 10; z++ ){
    for ( int y = 1; y < 10; y++ ){
    for ( int x = 1; x < 10; x++ ){

    //LOOKY HERE! You'll need this spot in a second

    }
    }
    }

    What mathematical action can i do between X, Y, and Z that will never return the same integer?

    ex (i = total when multiplying):
    x = 1;
    y = 2;
    z = 1;
    i =  2;

    but then when

    x = 1;
    y = 1;
    z = 2;
    i = 2;

    it returns the same integer... i have tried all i can think of (at least mentally) and they have not worked. Any ideas?
    " When the rich wage war its the Poor who die "
            Linkin Park



    Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

    You cannot buy your friends but you can buy them pizza - AzureBlade49

    BC_Programmer


      Mastermind
    • Typing is no substitute for thinking.
    • Thanked: 1140
      • Yes
      • Yes
      • BC-Programming.com
    • Certifications: List
    • Computer: Specs
    • Experience: Beginner
    • OS: Windows 11
    Re: (C++) Never return the same integer in three "for" statements
    « Reply #1 on: June 06, 2009, 08:04:28 PM »
    x+(y*10)+(z*100)
    I was trying to dereference Null Pointers before it was cool.

    liambiscuit

      Topic Starter


      Hopeful

      Re: (C++) Never return the same integer in three "for" statements
      « Reply #2 on: June 06, 2009, 08:06:43 PM »
      I...

      wait... are we allowed to curse?

      I <F-bomb>-ing love you!

      but i don't swing that way.

      so this conversation never happened =)
      " When the rich wage war its the Poor who die "
              Linkin Park



      Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

      You cannot buy your friends but you can buy them pizza - AzureBlade49

      BC_Programmer


        Mastermind
      • Typing is no substitute for thinking.
      • Thanked: 1140
        • Yes
        • Yes
        • BC-Programming.com
      • Certifications: List
      • Computer: Specs
      • Experience: Beginner
      • OS: Windows 11
      Re: (C++) Never return the same integer in three "for" statements
      « Reply #3 on: June 06, 2009, 08:08:22 PM »
      LOL

      it actually took me a minute or so to realize, that since your only going from 1 to 9 in the loops, you can just use the numbers as different place values.  :)

      Another thing you could do is simply use another variable, and increment it in the innermost loop and use that.
      I was trying to dereference Null Pointers before it was cool.

      liambiscuit

        Topic Starter


        Hopeful

        Re: (C++) Never return the same integer in three "for" statements
        « Reply #4 on: June 06, 2009, 08:13:58 PM »
        Well... i don't know what you mean... here is the main part of my code i was focused on...

        Code: [Select]
        for ( int z = 1; z < 10; z++ ){
        for ( int y = 1; y < 10; y++ ){
        for ( int x = 1; x < 10; x++ ){
        int i = x+(y*10)+(z*100);
        dbMakeObjectCube( i, 1 );
        }
        }
        }

        In DarkGDK (the framework i am using) each object is given a numerical ID to identify it, represented by 'i' in the above code. i would have repeat integers and not get more than 30 of them on screen (i think it is thirty, didn't count, didn't bother to do the math [i typed mouth at first =D ] )


        i am practically trying to make a clone of http://www.minecraft.net (typed that from head, if it doesn't work just google minecraft) next thing i think i can find in the documentation, figuring out the on-screen coordinate of an object.

        thanks, =)
        " When the rich wage war its the Poor who die "
                Linkin Park



        Whoever said that nothing is impossible has obviously never tried to slam a revolving door. -- Lauren

        You cannot buy your friends but you can buy them pizza - AzureBlade49