I use a sentinel value to let users signal when they finish: int x; while (cin >> x && x != -1) { sum += x; } reads integers until the user types -1. The condition cin >> x && x != -1 first reads a value, and only if that succeeds, checks if it is the sentinel.
This ordering prevents checking garbage values when input fails. Choose sentinels that are not valid data. For ages, -1 works. For counts, 0 works. Document the sentinel : cout << "Enter values (-1 to stop): "; so users know how to exit.