Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

C++ Code explanation?

Here is a nest loop in some code. Any help with what it means exactly would be greatly appreciated.

for (i = 1; i <= numlocker; i++)

{

x = 0;

for (j = 1; j <= numlocker; j++)

{

if ( i % j == 0)

x++;

}

if ( x % 2 != 0) {

cout << "Locker " << i << " is open";

cout <<endl;

}

}

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    It appears to be a lock pick algorithm. It consists of a pair of nested loops. The lock code appears to be a pair of integers less than some number called "numlocker". The inner loop increments X until the first number is found. It then uses this number along with the second until both match the code which opens the lock. However, I've never seen the symbol "%" used in C++ except in formatting text. Perhaps the above is something known as pseudo code which isn't really a language but rather a blueprint of how the algorithm works.

    Source(s): I program computers.
  • 1 decade ago

    You're missing the declaration and setting code for numlocker.

    Right now that's a error numlocker is not defined.

  • wg0z
    Lv 7
    1 decade ago

    in this context, % is the remainder (modulus) operator

Still have questions? Get your answers by asking now.