954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

map and for loops problem

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::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<

megatron21
Newbie Poster
3 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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.

mike_2000_17
Posting Virtuoso
Moderator
2,136 posts since Jul 2010
Reputation Points: 1,634
Solved Threads: 457
 

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

megatron21
Newbie Poster
3 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: