c - 布尔值的 Scanf
问题描述
我对此有点坚持,我有两个布尔变量,但我不希望它返回真或假,只需保存该值并在下面的表达式中使用它,但是当我尝试大学检查器中的代码时给了我这个错误,我不知道如何解决。该代码有效,但给出了错误。
#include <stdbool.h>
typedef enum { STARTUP, FREELANCERS, RURAL, SPECIALIZED, GENERALIST } tCentreType;
int main (int argc, char **argv) {
int id;
tCentreType Type;
int category;
int spaces;
float price;
float distance;
float occupation;
bool hasKitchen;
bool hasAuditorium;
int totalworkers;
float discount;
bool meetconditions;
bool needpromotion;
float totalprice;
int type;
float workcenter;
float realdiscount;
float monthlyprice;
/* Input */
printf("INPUT DATA \n");
printf("ID? (AN INTEGER) >>\n");
scanf("%d", &id);
printf("TYPE? (1-STARTUPS, 2-FREELANCERS, 3-RURAL, 4-SPECIALIZED, 5-GENERALIST) >>\n");
scanf("%d", &type);
printf("CATEGORY? (AN INTEGER) >>\n");
scanf("%d", &category);
printf("PRICE[EUR]? (A REAL) >>\n");
scanf("%f", &price);
printf("DISTANCE FROM CITY CENTER[KM]? (A REAL) >>\n");
scanf("%f", &distance);
printf("HAS KITCHEN? (0-FALSE, 1-TRUE) >>\n");
scanf("%d", &hasKitchen);
printf("HAS AUDITORIUM? (0-FALSE, 1-TRUE) >>\n");
scanf("%d", &hasAuditorium);
printf("OCCUPATION [PERCENT]? (A REAL) >>\n");
scanf("%f", &occupation);
printf("COWORKERS? (AN INTEGER) >>\n");
scanf("%d", &totalworkers);
printf("DISCOUNT [PERCENT]? (A REAL) >>\n");
scanf("%f", &discount);
/* expresion */
meetconditions = hasKitchen && (distance < 5) && (price <= 100) ;
needpromotion = (occupation > 50 ) && (distance <= 5) ;
workcenter=totalworkers / 2;
totalprice = price - (price *(discount/100));
monthlyprice = totalprice * workcenter;
/* Output */
printf("RESULTS \n");
printf("IS ACCEPTABLE (0-FALSE, 1-TRUE): %d\n", meetconditions);
printf("NEEDS PROMOTION (0-FALSE, 1-TRUE): %d\n", needpromotion);
printf("MONTHLY PRICE [EUR]: %.2f\n", monthlyprice);
return 0;
}
当我运行程序时,我遇到了这个错误,我整个早上都在尝试修复,但找不到解决方案。
错误:
main.c:38:10: warning: format '%d' expects argument of type 'int *', but argument 2 has type '_Bool *' [-Wformat=]
scanf("%d", &hasKitchen);
~^ ~~~~~~~~~~~
main.c:41:10: warning: format '%d' expects argument of type 'int *', but argument 2 has type '_Bool *' [-Wformat=]
scanf("%d", &hasAuditorium);
~^ ~~~~~~~~~~~~~~
解决方案
推荐阅读
- sql - SQL:如果符合条件,如何删除组中的所有项目?
- html - 有序列表中自定义数字的宽度和高度相等
- java - 限制 Spring JmsListener 创建的 JMS 连接
- python - zipimport.ZipImportError:无法解压缩数据;zlib 不可用 构建失败(Ubuntu 18.04 使用 python-build 20180424)EB CLI 安装程序
- react-native - React native 没有在 ios 模拟器中运行
- python - 在 matplotlib 注释中添加一行
- kotlin - TornadoFX DataGrid 未更新
- python - 使用 Python,导出 SQLite 模式
- c++ - 使用 openssl 的未定义参考错误
- c# - 如何更改剃须刀页面中注册页面的身份错误