gpt4 book ai didi

c - 我的代码返回 0 而不是正确的数字

转载 作者:行者123 更新时间:2023-11-30 20:30:13 25 4
gpt4 key购买 nike

这是说用户已经 0 秒大并且已经吃了 0 个奥利奥,尽管这些功能与其他有效的功能几乎相同。

我尝试根据评论更改它,但现在一切都返回为零。

这是一份基础 C 语言的家庭作业,我只是想以最简单的方式修复这段代码,提前谢谢您! :)

    #include <stdio.h>

int ComputeUserDays(int userAgeYears) {
int userAgeDays;

userAgeDays = userAgeYears * 365;
userAgeDays = userAgeDays + (userAgeYears / 4);

return userAgeDays;
}
int ComputeUserMinutes(int userAgeDays) {
int userAgeMinutes;

userAgeMinutes = userAgeDays * 24 * 60;

return userAgeMinutes;
}
int ComputeUserSeconds(int userAgeMinutes) {
int userAgeSeconds;

userAgeSeconds = userAgeMinutes * 60;

return userAgeSeconds;
}
int ComputeUserSneezes(int userAgeDays) {
int userAgeSneezes;

userAgeSneezes = userAgeDays * 4;

return userAgeSneezes;
}
int ComputeUserCalories(int userAgeDays) {
int userCalories;

userCalories = userAgeDays * 2000;

return userCalories;
}
int ComputeUserOreos(int userCalories) {
int userOreos;

userOreos = userCalories / 45;

return userOreos;
}

int main(void) {
int userAgeYears;
int userAgeDays = ComputeUserDays(userAgeYears);
int userAgeMinutes = ComputeUserMinutes(userAgeDays);
int userAgeSeconds = ComputeUserSeconds(userAgeMinutes);
int userCalories = ComputeUserCalories(userAgeDays);
int userSneezes = ComputeUserSneezes(userAgeDays);
int userOreos = ComputeUserOreos(userCalories);

printf("Enter your age in years: ");

scanf("%d", &userAgeYears);

printf("You are %d days old.\n", userAgeDays );

printf("You are %d minutes old.\n", userAgeMinutes );

printf("You are %d seconds old.\n", userAgeSeconds );

printf("You have sneezed %d times in your life.\n", userSneezes );

printf("You have expended %d calories in your life.\n", userCalories );

printf("You needed to eat %d Oreos to expend those calories.\n", userOreos );


return 0;
}

最佳答案

您需要将逻辑更改为:

   int userAgeYears; 
printf("Enter your age in years: ");
scanf("%d", &userAgeYears);
int userAgeDays = ComputeUserDays(userAgeYears);
int userAgeMinutes = ComputeUserMinutes(userAgeDays);
int userCalories = ComputeUserCalories(userAgeDays);


printf("You are %d days old.\n", userAgeDays );

printf("You are %d minutes old.\n", userAgeMinutes );
.
.
.

等等。

因为您没有刷新变量,所以您只是调用函数而不刷新它。

关于c - 我的代码返回 0 而不是正确的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54700521/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com