How do I solve the error: switch quantity not an integer and error: case label does not reduce to a an integral constant"

Viewed 70

I am using C language to make program that selects employees in a project team based on their average points achieved in various criteria like MVP, so the error am getting is in the switch statement that says error: switch quantity not an integer, and the second error is error: case label does not reduce to a an integral constant

Here is the code:

#include <stdio.h>

main() {
    printf("Google Team Selection\n\n");
    double a, b, c, sum, average;
    printf("Enter your Minimum Viable Product(MVP) points here:\n");
    scanf("%lf", &a);
    printf("Enter your Apprenticer Programmer points here:\n");
    scanf("%lf", &b);
    printf("Enter your consistency points here:\n");
    scanf("%lf", &c);
    printf("Enter your qocient points");
    sum = a + b + c;
    average = sum / 3.0;
    printf(" the sum is %lf and the average is %lf", sum, average);
    switch (average) {
      case ">55":
        printf("Congratulations you have been selected\n");
        break;
    }
}

So, I want my program to select employees whose average is above 55.

2 Answers

Switch requires an integer or a character or an expression that has as output either an int or a char. And the case need a constant-expression too. You can check the switch microsoft documentation.

In this case you should just use if-else.

So:

if (average > 55) {
   printf("Congratulations you have been selected\n");
}

You cannot use switch in C for your purpose: the switch expression (average) and the case expressions must be integers.

You should use a simple if statement:

    if (average > 55) {
        printf("Congratulations you have been selected\n");
    }
Related