remainder

Write your question here.

1
2
3
4
5
6
7
8
  double a,b,c,g;
    cout <<"Enter two whole numbers separated by space: ";
    cin >> a >> b;
    c = a / b;
    g = a % b;
    cout <<"The quotient of diving "<< a <<" by " << b <<" is "<< c <<endl;
    cout <<"The remainder of diving "<< a <<" by " << b <<" is "<< d<<endl;

i want to find the remainder of diving a by b but there is a error at line g =a%b; and i dont know why?
closed account (1vf9z8AR)
% is only for integer types
is there any way to alter values a anb b at only pne specifc line that doesnt modify the entire values of a and b as integer at all other lines
closed account (1vf9z8AR)
no you will definately lose data in converting from one type to another.Also there is no point of having a remainder for decimal division.

another.Also there is no point of having a remainder for decimal division.

Of course there is a point. What if you wanted to limit a decimal to a certain range?

suyashsing234 is right that in C++ you cannot use % for double types.
That is what fmod() is for: http://www.cplusplus.com/reference/cmath/fmod/
(Don't be confused by modf, they're different functions)

In many other languages (e.g. C#) you wouldn't have this problem it all.
Last edited on
Topic archived. No new replies allowed.