I have almost all of my PSET3 breakout program complete. I want to add different point values based on the color of the bricks. I have each row colored differently and now when trying to determine the color, it isn't working.

Here is what I tried.

if (getColor(object) == "RED")
{ points++; }
else if (getColor(object) == "YELLOW")
{ points += 2; }

It is stating that getColor(object) is returning an INT. I have no way to correlate the INT with the Literal String.

Oh, and in the instantiation of the bricks, I am using setColor to color the bricks.

1 Answer 1


It returns an int that represents a color. See http://www.programmingsimplified.com/c/graphics.h/colors for more info. Also google getColor for more explanation.

You could use the actual color numbers in your code, or you could add something like

#define RED 4
#define YELLOW 14

at the top of your program (and remove the quotes in the if tests).


HOWEVER, what happens depends on where you got the getColor function. I went back and tried to implement something like what you are doing to see exactly what was happening because it dawned on me that I was SETting colors with strings just like you are trying to get them. It didn't make sense. I did some digging and found another naming inconsistency in the Stanford Public Library that we are using. I couldn't find getColor in the SPL, so I dug deeper.

It turns out that the function does exist, with a different name: getColorGObject(object) - #include <spl/gobjects.h> If you change the function name to this, and switch to strcmp() it should work, with the color name in double quotes.

if ( strcmp(getColorGObject(object),"RED") == 0)

[end edit]

btw, I like the concept of points based on color. Nice job.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum housekeeping. ;-)

  • There are known issues with SPL that the documentation doesn't always match the actual contents, particularly with function names. IF you have one that doesn't work as expected, look at the header file and compare it to the docs. Sometimes, the function name doesn't match.
    – Cliff B
    Jul 2, 2015 at 23:05
  • Thanks so much. This worked perfectly. Jul 3, 2015 at 12:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .