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?
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 int
s.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With