+=怎么会这样
# include <stdio.h># define COVERAGE 200
int main (void)
{
int sq_feet;
int cans;
printf ("Enter number of square feet to be painted: \n");
while ( scanf("%d", &sq_feet) == 1 )
{
cans = sq_feet / COVERAGE;
cans = cans + ((sq_feet % COVERAGE == 0))? 0: 1; // 改成cans += ((sq_feet % COVERAGE == 0))? 0: 1; 则输出就不再是0
为什么?
printf ("You need %d %s of paint.\n", cans, cans == 1? "can": "cans");
printf ("Enter next value(q to quit): \n");
}
return 0;
}