Error: "expression must have integral or unscoped enum type"

47,744

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 wouldn't require the use of fmod(). It's important to understand that the modulo operator % works with ints.


As πάντα ρέι mentioned, there is also this: Can't 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.
Share:
47,744
Victor Martins
Author by

Victor Martins

Updated on July 09, 2022

Comments

  • Victor Martins
    Victor Martins almost 2 years

    So guys I'm new I tried looking up a solution however, I didn't really understand it that well, I'm writing shorthand to understand how they can be replaced with other pieces of code, so I ran across the modulus to which I added however it gives a "expression must have integral or unscoped enum type".

    I don't know enum type is exactly, they code doesn't run?

    #include<iostream>
    #include<string>
    using namespace std;
    
    int main() {
    
        double b, x, y, z, a, c;
    
        c, b, x, y, z, a, c = 100;
        x += 5;
        y -= 2;
        z *= 10;
        a /= b;
        c %= 3; // "c" seems to be giving out that error?
    
    
        cout << b << x << y << z << a << c;
    
    
        return 0;
    }
    

    the problem here is that "c" gives the "expression must have integral or unscoped enum type" error.

    I know what the modulus does, it gives the remainder of the division between 2 numbers, however I'm stumped in this case because should it gives a remainder? Is it syntactically wrong?

    • Khalil Khalaf
      Khalil Khalaf over 7 years
      You are applying some
    • Lee Daniel Crocker
      Lee Daniel Crocker over 7 years
      C is set to 100 here, but none of the others are set.
    • πάντα ῥεῖ
      πάντα ῥεῖ over 7 years
      Now the title makes sense :)
    • WhozCraig
      WhozCraig over 7 years
      I hesitate to assume you understand what c, b, x, y, z, a, c = 100; actually does. Judging by your remaining program, you don't. If that line didn't give a "expression result unused" warning (or something very similar), you need to crank up your compiler warnings.
    • Raindrop7
      Raindrop7 over 7 years
      it's illegal to use modulus with float and double use int, short,, instead you haven't initialized all variables! try: double b = 0, x = 0, y = 0, z = 0, a = 0, c = 0;
    • πάντα ῥεῖ
      πάντα ῥεῖ over 7 years
      @gsamaras I liked the title before your edit and after my dupe-hammer more :P
    • gsamaras
      gsamaras over 7 years
      @πάνταῥεῖ feel free to rollback! :) :) Earlier that day there was a question titled "Template killing me softly", fun day! :)
  • Slava
    Slava over 7 years
    I think he needs to use int instead, but it is not quite clear from OP's code
  • gsamaras
    gsamaras over 7 years
    @Slava I agree, but that's should be enough to get him started! :) Updated, thank you!
  • Victor Martins
    Victor Martins over 7 years
    thank you very much for the clarification, I see now that you cannot utilize the double data type for modulus i changed and I though I could assigned. Thank you all very much @gsamaras
  • gsamaras
    gsamaras over 7 years
    Yes @VictorMartins, but as I said, you can use fmod(), which is like the modulus operator for doubles! Is there a reason for not accepting the answer?