int main(){
int TIMES_TAKEN_JUICE, COUNTER =0, amount_of_Juice, TOTAL_JUICE_TAKEN;
float COST_OF_JUICE_TAKEN, JUICE_AMOUNT_TAKEN, COST_OF_JUICE, JUICE_COST_PER_OZ;
printf("What is the weight (in oz.) of the original container of OJ?n");
scanf("%d", &amount_of_Juice);
printf("What is the cost of the original container of OJ in dollars?n");
scanf("%f", &COST_OF_JUICE);
JUICE_COST_PER_OZ = COST_OF_JUICE / (float) amount_of_Juice;
printf("%f", &JUICE_COST_PER_OZ);
printf("How many times did your roommate take your juice?n");
scanf("%d", &TIMES_TAKEN_JUICE);
while(COUNTER < TIMES_TAKEN_JUICE){
printf("How much juice did your roommate take this time (in oz.)?n");
scanf("%d", &JUICE_AMOUNT_TAKEN);
COUNTER++;
TOTAL_JUICE_TAKEN += JUICE_AMOUNT_TAKEN;
COST_OF_JUICE_TAKEN = TOTAL_JUICE_TAKEN * JUICE_COST_PER_OZ;
if (COST_OF_JUICE_TAKEN >= 10.00)
{
printf("Your roommate owes you $10.00n");
}
}
return 0;
}
我不知道JUICE_COST_PER_OZ变量为什么不起作用。我已经试过了我能想到的所有可能的组合。
scanf
在变量名之前需要&
,因为它会修改它们。printf
没有,因为它只读取它们。将打印输出读取为:
printf("%f", JUICE_COST_PER_OZ);
风格评论:我建议您将所有变量小写。大写通常只用于常量,而不用于正则变量。