首页 > 解决方案 > 布尔值的 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);
~^ ~~~~~~~~~~~~~~

标签: cbooleanscanf

解决方案


推荐阅读