0

I`am a bit stucked witht this, I have two boolean variables but i dont want to this to return true or false, just save the value and use it in the expresion below, but when i try the code in the university checker gives me this error and i dont know how to fix it. The code works but gives an error.

#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;
}

When i run the program i ge this error, i have been trying to fix this whole morning and cant find a solution.

error:

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);
~^ ~~~~~~~~~~~~~~
Steve Summit
  • 45,437
  • 7
  • 70
  • 103
Tomaso
  • 15
  • 3
  • The warning tells you exactly what's wrong: `scanf` `%d` wants a pointer to an `int`, but you're passing a pointer to a `bool`, which is a different type. You could redeclare `hasKitchen` and friends as `int`. – Steve Summit Oct 01 '21 at 12:04
  • 1
    There is no direct scanf format specifier for `_Bool`. You need to use a temporary variable: `int temp; scanf("%d", &temp); hasKitchen = temp;` – pmg Oct 01 '21 at 12:05
  • 1
    For future questions: Correct and precise descriptions are important. "When i run the program" No. You do not run your program. You try to compile it which fails. You can only run your program after compilation was successfull. Besides that, ~5 lines of code would be sufficient to reproduce your problem. There is no need to throw that much code at your readers. – Gerhardh Oct 01 '21 at 12:19

0 Answers0