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;