-
Always rounding up
I'm trying to figure how much paint someone will need. I have this right here:
int gallonsPaint = 0;
double paintCost = 0;
gallonsPaint = (int)totalFootage / SQUARE_FOOTAGE;
Anything over 0 should be 1. If gallonsPaint is over 1 then I want to output 2. Anything over 2 should be 3. And so on. What should I do?
-
This is kind of a hack, but you could always do something similar to:
Code:
gallonsPaint=int(totalFootage/SQUARE_FOOTAGE+.999999999);
Thats if totalFootage or SQUARE_FOOTAGE is a double or float. If not, then cast them as one.
[edit] I'm pretty sure the math header has a ceiling function you could look into as well [/edit]
-
One option is to use function ceil().
Code:
#include <cmath>
.
.
gallonsPaint = static_cast<int> (std::ceil(totalFootage / SQUARE_FOOTAGE));