I am having hard time understanding what the problem is with my code here. Basically I have a map that contains Key objects as the key, and Block* as the value. The point of this for loop is to print out the values that the key contains on to the console in the form of a game board. However it is only printing one role, in a infinite loop. the variable r never gets incremented for some reason. if you guys could help that would be great. Thanks in advance!

for (int r=0; r<rows; r++){
            for (int c =0; c<columns; c++){
                std::string name = "__ ";
                for (std::map <Key, Block*>::iterator it = blocks.begin(); it != blocks.end(); ++it){
                    Key key = it->first;
                    int x = key.getX();
                    int y = key.getY();
                    if (r=y && c==x){
                        Block *block = it->second;
                        name = block->getBlockName();
                        break;
                    }
                    else {
                        name = "__ ";
                    }
                }
                std::cout<<name;//print one row
            }
            //start new row
            std::cout<<"\n";
        }

Simple typo:

if (r=y && c==x){

should be:

if (r == y && c == x){

(notice the double = signs.

**Please use code-tags in the future.

ahh i c thanks alot !! that solves the problem dumb mistake on my part

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.