num_red - count_red = red_pot;// all defined as 0
和
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;
}
}
答案 0 :(得分:5)
如果这是一种类C语言,则需要使用==
进行相等性检查,而不是=
。单=
用于赋值,以便:
int seven = 7;
int five = 5;
if (seven - five == 2) ...
没关系,但是:
int seven = 7;
int five = 5;
if (seven - five = 2) ...
即使汇编也不会做你期望的事情。
您的代码中有一个经典示例。细分:
if (count_black = 0) blah;
当blah
为零时,将不执行count_black
。 将 count_black
设置为零并坚决拒绝执行blah
,因为count_blah = 0
的结果为0(错误)。
如果你想要平等:
num_red - count_red == red_pot
确实如此,您需要根据其他两个“已知”变量分配其中一个变量(“未知”变量)。例如,如果已知num_red
和count_red
,请将red_pot
设置为:
red_pot = num_red - count_red;
或者,如果知道red_pot
和count_red
,请将num_red
设置为:
num_red = count_red + red_pot;