If you use functions for each case, the only advantage would be in a large switch statement. As long as code is indented enough, there shouldn't be much problem. Of course, if the issue is redundant code, that usually means that you can structure your code better. For example:
Code:
printf("The area of the ");
if (shape == 'r')
printf("rectangle");
else if (shape == 'c')
printf("circle");
// etc.
printf(" is %d\n", area); While it is effective, it isn't exactly ideal. Why not have a variable that holds the name of the shape? Inside the switch statement when figuring out the area of the shape, you could set a string to the value of "rectangle" or "square" or whatever, though the easy way of doing this requires <string.h> (<cstring> in C++, though std::string is better in C++) to be #included:
Code:
char shape_name[10]; //"rectangle" is 9 characters, plus the null terminator makes 10
switch (shape) {
case 'r':
strcpy(shape_name, "rectangle");
// rest of code for rectangle here
break;
case 'c':
strcpy(shape_name, "circle");
// rest of code for circle here
break;
//other cases and default
}
total = num1 * num2;
printf("The area of the %s is %lf\n", shape_name, total); Just an example of how it might be used. It simplifies the output and doesn't require very much extra code either. That way, there is no need to create your own function and no need to complicate the output.