Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C-输出值计算不正确_C_Output - Fatal编程技术网

C-输出值计算不正确

C-输出值计算不正确,c,output,C,Output,我刚刚开始学习如何编写代码,并决定尝试创建一个程序,根据要求的特定值计算一个人燃烧的卡路里量。然而,每当我运行它而不是根据它们的值得到计算值时,我总是得到值2686708。不管发生什么,我似乎都无法让它工作 //included libraries #include <stdio.h> #include <stdlib.h> #include <math.h> //constants #define WALKING_CAL 5 #define E

我刚刚开始学习如何编写代码,并决定尝试创建一个程序,根据要求的特定值计算一个人燃烧的卡路里量。然而,每当我运行它而不是根据它们的值得到计算值时,我总是得到值2686708。不管发生什么,我似乎都无法让它工作

//included libraries
  #include <stdio.h>
  #include <stdlib.h>
  #include <math.h>

//constants
#define WALKING_CAL 5
#define EXERCISING_CAL 10
#define EATING_CAL 40
#define DRINKING_CAL 20
#define CALORIES_PER_POUND 3500*/

//main function
int main() {

int current_weight, goal_weight;
int walking, exercise, drinking, eating;
int total_walking, total_exercising, total_eating, total_drinking;
int calories_burned, calories_gained;

printf("What is your current weight?\n");
scanf("%d", &current_weight);

printf("\nWhat is your goal weight?\n");
scanf("%d", &goal_weight);

total_walking = WALKING_CAL * walking;
total_exercising = EXERCISING_CAL * exercise;
total_eating = EATING_CAL * eating;
total_drinking = DRINKING_CAL * drinking;
calories_burned = (total_walking + total_exercising)- (total_eating + total_drinking);


if (goal_weight > current_weight){
    printf("\nHow many minutes do you walk per day?\n");
    scanf("%d", &walking);

    printf("\nHow many minutes do you exercise per day?\n");
    scanf("%d", &exercise);

    printf("\nHow many minutes do you drink per day?\n");
    scanf("%d", &drinking);

    printf("\nHow many minutes do you eat per day?\n");
    scanf("%d", &eating);


    printf("You gain %d calories per day.", &calories_burned);

  }
  return 0;
}
//包含的库
#包括
#包括
#包括
//常数
#定义步行_CAL 5
#定义第10部分
#定义饮食标准40
#定义饮用水标准20
#定义每磅3500卡路里*/
//主要功能
int main(){
int当前权重、目标权重;
步行、运动、饮酒、饮食;
int total_步行、total_运动、total_进食、total_饮水;
燃烧的热量,增加的热量;
printf(“您当前的体重是多少?\n”);
scanf(“%d”和当前重量);
printf(“\n您的目标体重是多少?\n”);
scanf(“%d”和目标重量);
总步行量=步行量*步行量;
总运动量=运动量*运动量;
总进食量=进食量*进食量;
总饮酒量=饮酒量*饮酒量;
燃烧的卡路里=(总步行+总锻炼)-(总饮食+总饮酒);
如果(目标权重>当前权重){
printf(“\n您每天步行多少分钟?\n”);
scanf(“%d”,步行(&W);
printf(“\n您每天锻炼多少分钟?\n”);
scanf(“%d”和“练习”);
printf(“\n您每天喝多少分钟?\n”);
scanf(“%d”、&d);
printf(“\n您每天吃多少分钟?\n”);
scanf(“%d”,&d);
printf(“你每天增加%d卡路里。”,&carries_burned);
}
返回0;
}
这是:

printf("You gain %d calories per day.", &calories_burned);
打印变量的地址,而不是变量的值(作为
int
,这反过来是未定义的行为,但至少对您来说似乎不会爆炸)

应该是:

printf("You gain %d calories per day.", calories_burned);
&

删除以下内容:

打印变量的地址,而不是变量的值(作为
int
,这反过来是未定义的行为,但至少对您来说似乎不会爆炸)

应该是:

printf("You gain %d calories per day.", calories_burned);

删除
&

#define carries_PER_POUND 3500*/
上不应有结束注释符号。此外,您打印了一个整数,并向其传递了一个指针:day。“,燃烧的卡路里);此外,在使用变量进行计算之前,您还需要输入变量!我建议你开始学习C++,而不是C,使用C++的可能性比较小。在我测试这个东西之前,我已经注释掉了这个定义部分,我错过了这个注释。谢谢大家的帮助。我终于让它按我想要的方式工作了。
\define carries\u PER\u POUND 3500*/
行上不应该有关闭注释符号。此外,您打印一个整数,并传递一个指向它的指针:每天。“,燃烧的卡路里);此外,在使用变量进行计算之前,您还需要输入变量!我建议你开始学习C++,而不是C,使用C++的可能性比较小。在我测试这个东西之前,我已经注释掉了这个定义部分,我错过了这个注释。谢谢大家的帮助。这是一个常见的新到C程序员错误,因为对于
scanf()
,您需要
&int\u variable
,而对于
printf(),您只需要
int\u variable
--这是因为scanf需要更改
int\u变量的值,而printf只需要查看它。这是一个常见的new-to-C程序员错误,因为对于
scanf()
,您需要
&int\u变量
,而对于
printf()
——这是因为scanf需要更改
int\u变量的值,而printf只需要查看它。