我正试着为我的C编程课写一个程序。标题中的错误在我以零错误和警告运行程序后不断出现。这是我的密码

/*
   Write a program that contains the function calories() that is to accept a long integer number total and the addresses of the integer variables pizza, chips, apples, and mustard.
   The passed long integer represents the total number of calories you are able to consume in this meal, and the function is to determine the
   number of calories in slices of pizza, bags of chips, apples,
   and teaspoons of mustard in the passed value, writing these values directly into the respective variables declared in the calling function.

   This function will be called from the main program and when it returns to main, it will print out the values of variables pizza, chips, apples, and mustard.

   The calories in our favorite foods are in this order:
   pizza--385 calories each slice
   chips--170 calories each bag
   apple--80 calories each
   mustard--5 calories each tsp.
   For example, if I enter a total amount of calories of 1050, I can eat:
   2 slices pizza @ 770 calories (1050 - 770 = 280 calories remain)
   1 bag of chips @ 170 calories (280 - 170 = 110 calories remain)
   1 apple @ 80 calories (110 - 80 = 30 calories remain)
   6 tsp. mustard @ 30 calories
   */
#include <stdio.h>
int main()
{
    int calorie(int, int , int, int);

    int total, pizza, chips, apples, mustard, sum, sum1, sum2, sum3;

    pizza = 385;
    chips = 170;
    apples = 80;
    mustard = 5;

    printf("How many calories do you want to consume during your meal?");
    scanf("%d", total);

    total=calorie(pizza, chips, apples, mustard);


    printf("Pizza: %.2d", &pizza);
    printf("Chips: %.2d", &sum1);
    printf("Apples: %.2d", &sum2);
    printf("Mustard: %.2d", &sum3);

    return 0;

}

int calorie(pizza, chips, apples, mustard)
{
    int clfp, sum1, sum2, clfa, clfc, sum3, calorie;

    pizza = calorie/pizza;
    sum1 = calorie-pizza; /*calories left from pizza*/

    sum1 = clfp/chips;
    clfc = clfp-chips; /*calories left from chips*/

    sum2 = clfc/apples; /*calories life from apples*/
    clfa = clfc-apples ;

    sum3 = clfa/mustard;

    return pizza, sum1, sum2, sum3;
}

最佳答案

1)变更

int calorie(int, int , int, int);


int calorie(int *, int *, int *, int *); // send pointers, so that you can update them in function call.

2)变更通知
calorie(pizza, chips, apples, mustard);


calorie(&pizza, &chips, &apples, &mustard); // send address of variables.

3)变更退回
return pizza, sum1, sum2, sum3;


return 0; // to indicate success.

4)变更
printf("Pizza: %.2d", &pizza);
printf("Chips: %.2d", &sum1);
printf("Apples: %.2d", &sum2);
printf("Mustard: %.2d", &sum3);


printf("Pizza: %.2d", pizza);
printf("Chips: %.2d", sum1);
printf("Apples: %.2d", sum2);
printf("Mustard: %.2d", sum3);

5)变更
scanf("%d", total);


scanf("%d", &total);

关于c - 进程返回-1073741819(0xC0000005),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23332622/

10-12 14:24