I'm trying to do a really simple calculation in C++
double area()
{
return (base*height)/2;
}
where base
and height
are type int
- though when I supply base
and height
values of 5
and 5
(they are declared earlier in the file) - I get back 12
, when I should be getting back 12.5
considering the double
return type.
Am I using the return correctly, or should I be trying to use setprecision()
or trying to cast before returning?