0
我剛剛開始學習如何編寫代碼並決定嘗試創建一個程序,該程序可以基於某些要求的值來計算人們燃燒的卡路里量。然而,每當我運行它而不是基於它們的值獲取計算值時,我總是得到值2686708.無論如何,我似乎無法使它工作。C - 輸出值計算不正確
//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", ¤t_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;
}
'#define CALORIES_PER_POUND 3500 * /'行不應該有關閉註釋符號。 – 2014-09-12 15:48:25
此外,你printf一個整數,你傳遞一個指針:每天。「,calories_burned); – 2014-09-12 15:49:07
你也需要輸入你的變量*之前*做他們的計算! – 2014-09-12 15:49:47