0

Why Error?

#include <iostream> #include <cmath> using namespace std; int main() { auto b = 1.95; //auto c = floor(b*10)%10; cout<<floor(b*10)%10<<endl; //cout<<c; return 0; } floor(b) - - int floor(b*10)--int floor(b*10)%10--Error Why?

28th Apr 2021, 9:49 PM
Mohammad Mehedi Hasan
Mohammad Mehedi Hasan - avatar
1 Respuesta
+ 3
The type returned from floor(b*10) is a double. The operands on both sides of the modulus operator % need to be of type int. You can fix it by casting the value returned to an int. cout << (int)floor(b*10)%10<<endl;
28th Apr 2021, 11:40 PM
ChaoticDawg
ChaoticDawg - avatar