what is this doing??

This is a discussion on what is this doing?? within the C++ Programming forums, part of the General Programming Boards category; I have been looking at code for a magic square problem and have no idea what this code is doing. ...

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    1

    what is this doing??

    I have been looking at code for a magic square problem and have no idea what this code is doing. Could you guys please help me?

    Code:
    for (count = 2; count <= max_count; count++)
        {
        row = (i - 1 < 0) ? (size - 1) : (i - 1);  // up
        col = (j - 1 < 0) ? (size - 1) : (j - 1);  // left
    
    
    //i know what this is doing just need help with the above
    
    
        if (square[row][col] != 0)
          {
          i ++;
          i = i % size;
          }
        else
          {
          i = row;
          j = col;
          }
        square[i][j] = count;
        }

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Location
    Mt. Prospect, IL
    Posts
    2,572
    its another way of saying if else...

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    As in
    Code:
    if ( i - 1 < 0 ) {
      row = size - 1;
    } else {
      row = i - 1;
    }
    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.

Popular pages Recent additions subscribe to a feed

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