#include <iostream>
using namespace std;
class deci {
float a;
public:
deci(float b)
{
a = b;
}
void operator-()
{
a = a - 0.1;
cout << a;
}
};
int main()
{
float a;
cin >> a;
deci b(a);
-b;
return 0;
}
Asked
Active
Viewed 74 times
1

Josh Kelley
- 56,064
- 19
- 146
- 246

Pallav Laddha
- 51
- 6
-
1Just saying, the negative operator shouldn't change the object, but should return the changed object. – Arnav Borborah Sep 08 '17 at 18:03
-
3Your output is `1.49012e-09` which is nearly zero because `0.1f - 0.1f == 0.0f ~ 1.0e-9` – Cory Kramer Sep 08 '17 at 18:04
-
2[What does E mean in 9.0122222900391E-5?](https://math.stackexchange.com/questions/6273/what-does-e-mean-in-9-0122222900391e-5) [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – Bernhard Barker Sep 08 '17 at 18:05
-
1Visual Studio says deci is ambiguous because it's a typedef for std::ratio<1i64, 10i64> something. – Zebrafish Sep 08 '17 at 18:06
-
when i use double i get 0 as output i dont know what is wrong when i use float? – Pallav Laddha Sep 08 '17 at 18:07
-
new to this platform thank you guys for the help! – Pallav Laddha Sep 08 '17 at 18:09
-
@Zebrafish it is, if you search on CPPReference, you get `std::ratio` – Arnav Borborah Sep 08 '17 at 18:11