You still don't need to use gigantic switch statements to handle that sort of thing.
Think of it this way. You have two operations you can do to the number: add 3 or multiply by 3. You either perform these options or you don't. So it's sort of like using binary numbers, where 0s mean you don't perform the operation and 1s mean you do. In this case, the possible operations are 00 (ignored), 01, 10, and 11. Do you see? With three operations, you'd have 000, 001, 010, 011, 100, 101, 110, and 111.
I think that this code needs to be implemented in two parts. You have the code which actually adds or multiplies by three -- this could probably be a switch statement -- and you have code which calls this other code for every possible combination.
Here's what I'm envisioning:
Code:
int perform_operation(int x, int y, const char *operation) {
if(!strcmp(operation, "--add")) return x + y;
/* ... */
return x;
}
for each combination(arguments) {
perform_operation(number, argument);
}
Also, this actually looks like it might work quite well if you implemented it recursively. It might be difficult otherwise.
Code:
void do_operation(int x, int value, char *argv[]) {
if(argv[1]) do_operation(x, value, argv+1);
x = perform_operation(x, value, *argv);
print_possible_value(x);
if(argv[1]) do_operation(x, value, argv+1);
}
Do you see what I'm saying? I hope it's legible
[edit] Also see this Wikipedia entry: http://en.wikipedia.org/wiki/Permutation [/edit]