It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center
                            
                        
                    
                
                                7年前关闭。
            
                    
说明:
设定冷冻酸奶的金额。大人会给孩子吃一定比例的东西。每盎司酸奶为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;
}

最佳答案

数学很简单:

childounces = totalounces / (1+ratio);
adultounces = totalounces - childounces;

关于c - 用C语言进行简单数学运算? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12719635/

10-11 23:11
查看更多