Question

could some one help. getting error with these 2 lines of code. num_red - count_red = red_pot;// all defined as 0 and

while (count_red = 0 && count_yellow = 0 && count_green = 0 && count_brown = 0 && count_blue = 0 && count_pink = 0)
        {
            if (count_black = 0)
            {
                score = score + 7;
                printf("Score: %d\n", score);
                num_balls = num_balls - 1;
            }

        }
Was it helpful?

Solution

If that's a C-like language, you need to use == for equality checks, not =. The single = is for assignment so that:

int seven = 7;
int five = 5;
if (seven - five == 2) ...

is okay, but:

int seven = 7;
int five = 5;
if (seven - five = 2) ...

will, even if it compiles, not do what you expect.

You have a classic example in your code. The segment:

if (count_black = 0) blah;

will not execute blah when count_black is zero. It will set count_black to zero and steadfastly refuse to ever execute blah, since the result of count_blah = 0 is 0 (false).


If you want the equality:

num_red - count_red == red_pot

to be true, you need to assign one of those variables (the "unknown" one) based on the other two "known" ones. For example, if num_red and count_red are known, set red_pot with:

red_pot = num_red - count_red;

Alternatively, if red_pot and count_red are known, set num_red with:

num_red = count_red + red_pot;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top