Don't you get a warning or two when you compile your code? If not, you should really crank up the warning level. On gcc, it's -Wall for starters. This question has some background and details on C and C++ warnings.
The compiler tells you what's wrong:
robert:~$ gcc modulo.cpp
modulo.cpp: In member function ‘float Modulo::operator%(const Modulo&)’:
modulo.cpp:15:5: warning: no return statement in function returning non-void [-Wreturn-type]
You calculate result, but never do anything with it. With -Wall you'd also get a warning about the unused variable. Bottom line: there is no return value, and still you try to print it. At best you get nan, for me it just crashes and burns.
Add return result; to float operator%(const Modulo& other):
float operator%(const Modulo& other) {
float result = float(x / (float) other.x);
return result;
}
Besides that, don't use this code in real life: it's very confusing to redefine the modulo operator to do division. There's a / operator for that. You'll confuse the heck out of yourself and your peers. Unrelated, but also important: get in the habit of consistently indenting your code. It makes it much easier to read. And enable all compiler warnings.
5 % 4still calculates the remainder of integer division.