自动计算批次的价格

时间:2015-05-23 13:11:00

标签: c

我正在努力赚钱。现在我正在做饼干,并且正在利用各种成分的价格和他们持续获得多少批次来获取利润,但是,LCM是300,所以我不能真正手动完成。那我该如何自动完成呢?

#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>

#define buttergram 500
#define sugargram 1000
#define eggsgram 12
#define flourgram 1000
#define bakingpowdergram 100
#define chocchipsgram 200

#define butterbatch 125
#define sugarbatch 200
#define eggsbatch 2
#define flourbatch 300
#define bakingpowderbatch 4
#define chocchipsbatch 200

int main()
{
    /* Variables */

    float butter;
    float sugar;
    float eggs;
    float flour;
    float bakingpowder;
    float chocchips;

    char pound = 156;

    /* Actual Code */

    printf("How much were the 500g of Golden Cow Butter?: %c" ,pound);
    scanf("%f" ,&butter);
    printf("\n");
    printf("How much were the 1000g of Soft Brown Sugar?: %c" ,pound);
    scanf("%f" ,&sugar);
    printf("\n");
    printf("How much were the 12 Eggs?: %c" ,pound);
    scanf("%f" ,&eggs); 
    printf("\n");
    printf("How much were the 1000g of Flour?: %c" ,pound);
    scanf("%f" ,&flour);    
    printf("\n");
    printf("How much were the 100g of Baking Powder?: %c" ,pound);
    scanf("%f" ,&bakingpowder);
    printf("\n");
    printf("How much were the 200g Chocolate Chips?: %c" ,pound);
    scanf("%f" ,&chocchips);    
    printf("\n");


    printf("The butter will last %d batches which means you are paying %c%.2f for 1 batch.\n" ,buttergram/butterbatch ,pound ,butter/(buttergram/butterbatch));
    printf("The sugar will last %d batches which means you are paying %c%.2f for 1 batch.\n" ,sugargram/sugarbatch ,pound ,sugar/(sugargram/sugarbatch));
    printf("The eggs will last %d batches which means you are paying %c%.2f for 1 batch.\n" ,eggsgram/eggsbatch ,pound ,eggs/(eggsgram/eggsbatch));
    printf("The flour will last %d batches which means you are paying %c%.2f for 1 batch.\n" ,flourgram/flourbatch ,pound ,flour/(flourgram/flourbatch));
    printf("The baking powder will last %d batches which means you are paying %c%.2f for 1 batch.\n" ,bakingpowdergram/bakingpowderbatch ,pound ,bakingpowder/(bakingpowdergram/bakingpowderbatch));
    printf("The chocolate chips will last %d batch which means you are paying %c%.2f for 1 batch.\n" ,chocchipsgram/chocchipsbatch ,pound ,chocchips/(chocchipsgram/chocchipsbatch));

    /* How many Batches ingredients last */

    int butterbatches = buttergram/butterbatch;
    /* 4 */
    int sugarbatches = sugargram/sugarbatch;
    /* 5 */
    int egssbatches = eggsgram/eggsbatch;
    /* 6 */
    int flourbatches = flourgram/flourbatch;
    /* 3 is actually 3.33 */
    int bakingpowderbatches = bakingpowdergram/bakingpowderbatch;
    /* 25 */
    int chocchipsbatches = chocchipsgram/chocchipsbatch;
    /* 1 */

    printf("Remember a batch is 24 cookies.\n");
    printf("Batch 1: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,butter+sugar+eggs+flour+bakingpowder+chocchips ,pound ,(butter+sugar+eggs+flour+bakingpowder+chocchips)/24);
    printf("Batch 2: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,chocchips ,pound ,chocchips/24);
    printf("Batch 3: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,chocchips ,pound ,chocchips/24);
    printf("Batch 4: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,flour+chocchips ,pound ,(flour+chocchips)/24);
    printf("Batch 5: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,chocchips+butter ,pound ,(chocchips+butter)/24);
    printf("Batch 6: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,sugar+chocchips ,pound ,(flour+chocchips+butter)/24);
    printf("Batch 7: %c%.2f has been spent which is %c%.2f per cookie.\n" ,pound ,eggs+chocchips ,pound ,(eggs+chocchips)/24);
    printf("This cycle goes on for 300 batches so until I find an automatic method you get the idea.");

    return(0);
}

1 个答案:

答案 0 :(得分:0)

在这里,我建议您在尝试编写这些类型的程序之前,先打开您的书籍或其他任何学习资源,然后再进一步学习。

当你学到很多困难时,当你拥有大量的元素时,你不想为每一件你可以单独使用它们的东西编写单独的代码。< / p>

在这里,您要了解控制结构,for/while/do-while循环,存储可索引元素的数组(允许您从它们的集合中检索第n个元素),甚至可能是文件I / O和{ {1}}定义您自己的数据类型。