c++ – Error: expression must have integral or unscoped enum type

c++ – Error: expression must have integral or unscoped enum type

c is double, thus you cannot use the modulo operator %.

Use fmod() instead.

So change this:

c %= 3

to this:

c = fmod(c, 3);

As Slava mentioned, you could have used an int instead, like this:

int c = 5; // for example
c %= 3

which wouldnt require the use of fmod(). Its important to understand that the modulo operator % works with ints.


As πάντα ρέι mentioned, there is also this: Cant use modulus on doubles?


As a side note Victor, you have so many variables, but most of them are unused and or uninitialized. Did you compile with all the warnings enabled? Here is what I get when compiling your original code (with the line that generates the error commented out):

C02QT2UBFVH6-lm:~ gsamaras$ g++ -Wall main.cpp 
main.cpp:9:5: warning: expression result unused [-Wunused-value]
    c, b, x, y, z, a, c = 100;
    ^
main.cpp:9:8: warning: expression result unused [-Wunused-value]
    c, b, x, y, z, a, c = 100;
       ^
main.cpp:9:11: warning: expression result unused [-Wunused-value]
    c, b, x, y, z, a, c = 100;
          ^
main.cpp:9:14: warning: expression result unused [-Wunused-value]
    c, b, x, y, z, a, c = 100;
             ^
main.cpp:9:17: warning: expression result unused [-Wunused-value]
    c, b, x, y, z, a, c = 100;
                ^
main.cpp:9:20: warning: expression result unused [-Wunused-value]
    c, b, x, y, z, a, c = 100;
                   ^
main.cpp:10:5: warning: variable x is uninitialized when used here [-Wuninitialized]
    x += 5;
    ^
main.cpp:7:16: note: initialize the variable x to silence this warning
    double b, x, y, z, a, c;
               ^
                = 0.0
main.cpp:11:5: warning: variable y is uninitialized when used here [-Wuninitialized]
    y -= 2;
    ^
main.cpp:7:19: note: initialize the variable y to silence this warning
    double b, x, y, z, a, c;
                  ^
                   = 0.0
main.cpp:12:5: warning: variable z is uninitialized when used here [-Wuninitialized]
    z *= 10;
    ^
main.cpp:7:22: note: initialize the variable z to silence this warning
    double b, x, y, z, a, c;
                     ^
                      = 0.0
main.cpp:13:5: warning: variable a is uninitialized when used here [-Wuninitialized]
    a /= b;
    ^
main.cpp:7:25: note: initialize the variable a to silence this warning
    double b, x, y, z, a, c;
                        ^
                         = 0.0
main.cpp:13:10: warning: variable b is uninitialized when used here [-Wuninitialized]
    a /= b;
         ^
main.cpp:7:13: note: initialize the variable b to silence this warning
    double b, x, y, z, a, c;
            ^
             = 0.0
11 warnings generated.

c++ – Error: expression must have integral or unscoped enum type

Leave a Reply

Your email address will not be published.