assert - C语言中的断言
问题描述
所以我尝试编写一个代码将 kmph 转换为 m/s 并想使用 Assert 进行验证。
这是我写的一段代码。尝试与打印语句比较时该值是正确的,但断言给出错误
#include <stdio.h>
#include <assert.h>
float convert(float num);
int main()
{
float kmph;
printf("Enter Velocity in Kmph\n");
scanf("%f", &kmph);
printf("Velocity in m/s is %f\n", convert(kmph));
assert(convert(1) == 0.277778);
assert(convert(18) == 5.0);
return 0;
}
float convert(float num)
{
float mps;
mps = num * 0.277778;
return mps;
}
错误描述:
Enter Velocity in Kmph
1
Velocity in m/s is 0.277778
a.out: program4.c:14: main: Assertion `convert(1) == 0.277778' failed.
Aborted (core dumped)
解决方案
推荐阅读
- snowflake-cloud-data-platform - Teradata 到雪花的转换
- python - 打印跟踪失败消息。卢卡斯·卡纳德。开放式CV
- angular - 找不到模块“@ng-bootstrap/ng-bootstrap”或其任何相应的类型声明
- json - 火花 | 无法创建 FileClient | 读取 json | 斯卡拉
- mysql - Mysql 数据库在每次 docker 重启时消失
- python - 如何使用 SQLAlchemy、pydantic 和 FastAPI 处理聚合查询结果
- excel - 如何隐藏非活动工作表的标题,vba?
- flutter - 如何修复编写颤振模型时出现的错误空错误?
- tensorflow - 如何在 Tensorflow 对象检测中跳过不良图像?
- swift - 从 Yelp 获取类别