Suppose you have 17 markers and want packs of 5. You can make three full packs, with two markers left over. Two C++ operators answer those two questions.
When both operands are integers, / performs integer division. It discards the fractional part, truncating toward zero. For the nonnegative counts in this lesson, that means the number of complete groups. % gives the integer remainder.
#include <iostream>
int main() {
int markers = 17;
int perPack = 5;
std::cout << "Full packs: " << markers / perPack << "\n";
std::cout << "Left over: " << markers % perPack << "\n";
return 0;
}
This prints Full packs: 3 and Left over: 2. The calculation fits back together: full packs multiplied by pack size, plus the leftover count, recovers the original number of markers.
The divisor must not be zero. There is no meaningful number of zero-sized groups, and integer division or remainder by zero is unsafe. The starter supplies a positive group size; keep it unchanged.
Integer division is not always the right operation. If you wanted an average that can have a fractional part, discarding that fraction would lose information. The next lesson shows how to request floating-point division. Here, complete groups are exactly what we need.
Your data describes 29 name tags bundled in groups of 6. bundles answers how many full groups you can make; loose answers how many tags remain outside those groups. Replace their temporary zeros separately. Neither calculation should change tags, because both use the same starting supply.
bundles using integer division of tags by perBundle, producing Bundles: 4.loose using the remainder of tags divided by perBundle, producing Loose tags: 5.Edit main.cpp, press Run to inspect the Console, then Submit to check these results.