Decimal Division function

Oct 17, 2021 at 3:37pm
Hi, I need some help with my Calculator class' function. I have it to add, subtract, multiply, and divide. I need a decimal divisor script! How do I make it divide divis by divid? Example 2/5 = 0.4, not 0. It needs to return the value in
 
return divid/divis      // divis == 5, divid == 2 

and it's rounding! Help!


1
2
3
4
  calculator::divide(int divid,int divis)    // here's the function declaration
  {
    return divid/divis;
  }
Oct 17, 2021 at 3:38pm
1
2
3
4
double calculator::divide( int divid, int divis )
{
   return ( divid + 0.0 ) / divis;
}
Last edited on Oct 17, 2021 at 3:41pm
Oct 17, 2021 at 3:58pm
@lastchance Thanks for the fast response! Will try!
Topic archived. No new replies allowed.