gpt4 book ai didi

c - 用 c 修复百分比计算器?

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

我尝试使用此代码,但在用户输入总分后控制台崩溃

#include <stdio.h>
#include <string.h>

int main () {
int part, total;
int whole = 100;
printf("What is total score of the exam?\n");
scanf("%d", part);
printf("Enter your score on the exam\n");
scanf("%d", total);
printf(total/part * whole);
return 0;
}

最佳答案

简短的回答,这样这个问题就不会悬而未决。您应该启用编译器警告并学会解释它们,这样您就可以更轻松地自己解决问题。在 GCC 上,您可以添加 -Wall 编译器选项来显示查看此类问题所需的常见警告。

#include <stdio.h>
#include <string.h>

int main ()
{
int part, total;
int whole = 100;

printf("What is total score of the exam?\n");
scanf("%d", &part); /* address of part needed, not its value*/

printf("Enter your score on the exam\n");
scanf("%d", &total); /* address of total needed, not its value*/

printf("%d", total/part * whole); /* printf expects a string as its first parameter */
return 0;
}

关于c - 用 c 修复百分比计算器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40813875/

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