|
|
|
|
try modulus division 1 2 3 4 5 6 7 8 9 10 #include <iostream> using namespace std; int main() { cout << "5 % 3 = " << 5 % 3 << endl; cout << "4 % 3 = " << 4 % 3 << endl; cin.ignore(); return 0; } |
|
|
If you're only worried about getting it to work when you divide by three, the following logic will help:
Basically, you're grabbing the remainder and seeing whether it is big enough to warrant incrementing the value of your quotient. |
Edit: or - you can use the floor function floor() - since you want to round down if the decimal part is below .5? You can add .5 to whatever result you get, then use the floor function. That will round to the closest integer. example 4.0/3 = 1.33 -> 1.33 + .5 = 1.83 -> floor(1.83) = 1 92.0/3 = 30.66 -> 30.66 + .5 = 31.16 -> floor(31.16) = 31 |