0
Can’t understand why this doesn’t work
#include <iostream> using namespace std; int main() { float a = 60; float x = a % 7; cout << x; return 0; } This is the error message: ..\Playground\: In function 'int main()': ..\Playground\:7:14: error: invalid operands of types 'float' and 'int' to binary 'operator%' float x = a % 7; ~~^~~
1 Odpowiedź
0
the '%' operator works only with integers
you could try casting the variable 'a' to an 'int' or set 'a' as int to begin with and assign to 'x' if you set 'x' to int as well
int main()
{
float a = 60;
int x = (int)a % 7;
cout << x;
return 0;
}