c - 我正在使用 Visual Studio 2019,我目前正在用 C 语言制作一些关于身高和体重的方程式,这是否非常相似?
问题描述
我只想知道我是否犯了任何错误(考虑到我的代码中有 11 个警告和多条绿线,这很可能是这样。)
#include <stdio.h>
#include <conio.h>
int main(void)
{
int heightBody, weightBody, heightAndWeightResult; // Variables
printf("Enter Body Weight: ", weightBody); //Manual Input
scanf_s("%d", &weightBody);
printf("Enter Body Height: ", heightBody);// Manual Input
scanf_s("%d", &heightBody);
heightAndWeightResult = heightBody + weightBody; // to calculate the height and weight
printf("Body Result: ", heightAndWeightResult);
getch();
return 0;
}
关于错误消息,存在“参数过多”错误;使用未初始化的内存;和返回值忽略 getch();
解决方案
- 给变量初始值
IE
int heightBody = 0, weightBody = 0, heightAndWeightResult;
检查返回值
scanf_s
- 阅读手册页不需要前两个中的变量
printf
IE
printf("Enter Body Weight: ");
printf("Enter Body Height: ");
- 最后需要一个格式说明符
printf
IE
printf("Body Result: %d", heightAndWeightResult);
也许值得您阅读printf
和scanf_s
推荐阅读
- javascript - Protractor/Jasmine 可以等待 20 分钟进行测试执行吗?
- python - 使用 Selenium 从 h3 类名中获取标题列表
- amazon-web-services - 如何使用 AWS 应用程序负载均衡器将 https 重定向到带有 www 的 https?
- python - 来自集合 Python 的随机数
- eclipse - Eclipse 中缺少 c/c++ 单元测试支持?
- heroku - “这个应用程序还没有进程类型”尽管一切都已部署
- ihp - 数据构造函数不在范围内:无法识别的编译指示
- python - Imblearn SMOTE:如何为多类不平衡数据集设置 sample_strategy 参数?
- python - Pythinic spark 作业正在尝试从某个地址获取某些内容并失败
- jmeter - Jmeter灵活文件写入头问题