No comments on the algorithm itself. But iI have many style improvements a interviewer probalyprobably looks for.
You should better read in as std::stringstd::string and convert the result to integer after if possible:
for (;;) {
std::string input;
std::cin >> input;
for (;;) {
std::string input;
std::cin >> input;
if (is_convertible_to_integer(input)) { // write a function to check if is convertible to unsigned int
// convert to string
break;
}
}
}
This can be probalyprobably in a function as well like unsigendunsigned int read_unsigend_int();
The next thing I wonder. Do you really need unsigendunsigned int? Often it is not worth the hasselhassle. It can intriduceintroduce hard to spot errors: https://stackoverflow.com/questions/22587451/c-c-use-of-int-or-unsigned-int
Then you create a class just for solving basically some computations. In this case iI think its overengineeringover-engineering. It could be simply solved by using free standing functions.
Unlike in some other Programming languages werewhere everything is a class you can just use free standing functions.
However it is a good idea to wrap youreyour functions and classes in its own namespace to prevent name clashes. So do something like:
AnnotherAnother small thing:
Also you should not use std::endl for a newline. I even saw it in many wrong books. std::endlstd::endl gives you a newline and an expensive flushing operation of the buffer. Instead just use \n.