-1

说明:设置冷冻酸奶的金额。大人会按一定比例给孩子吃。每盎司酸奶是 0.49。出于某种原因,这不起作用,我不知道为什么。我知道哪一行造成了麻烦,我用粗体和斜体表示。

#include <stdio.h>

# define SALES_TAX 0.065
# define PRICE_PER_OZ 0.49

int main()
{
    float totalcash;
    double ratio;
    double totalbeforetax;
    float totalounces;
    double adultounces;
    double childounces;


    //user input for total cash and scanning
    printf("How many dollars do you have for frozen yogurt?\n");

    //scan in total cash
    scanf("%f", &totalcash);

    //user input for ratio and scanning
    printf("What is the ratio of yogurt that you'll get to your child?\n");

    //scan in ratio
    scanf("%lf", &ratio);

    //solve for values
    totalbeforetax = (totalcash)/(1+SALES_TAX);
    totalounces = totalbeforetax/(PRICE_PER_OZ);
    //adultounces = childounces*ratio;
    ***adultounces = (totalounces-adultounces)*(ratio);***
   // childounces = adultounces/ratio;
    childounces = totalounces-adultounces;



    //output
    printf("You will get %.2lf ounces of yogurt.\n",adultounces);
    printf("Your child will get %.2lf ounces of yougrt\n", childounces);

    return 0;
}
4

2 回答 2

0

adultounces在计算中使用它之前,您尚未初始化。你需要做一些代数来弄清楚如何根据你所拥有的进行计算。

暗示:

adult + child = ratio*child + child = total
于 2012-10-04T02:59:32.350 回答
0

数学很简单:

childounces = totalounces / (1+ratio);
adultounces = totalounces - childounces;
于 2012-10-04T03:03:10.010 回答