Your idea would work in a scripting language, but a C++ (or C) program does not know the variable names after it is compiled. Why don't you just pass in an array?

EDIT: Actually, another idea is...