You are missing
break
statements at the end of your
case
statements. It should be:
switch(c) {
case 'D' : scanf("%d", &a); break;
case 'H' : scanf("%x", &a); break;
case 'O' : scanf("%x", &a); break;
default : printf("Wrong Base!\n");
}
Otherwise, you get what is called a "fall-through", that is if cis 'D', then case 'D' is performed, and then execution "falls through" to case 'H' and so on. More recent compilers (gcc and clang, at least), may issue a warning for this, if told to do so. There
are situations where you do want to have fall-through behaviour, so it's sometimes useful to have it. Related is the situation where you have more than one case value for which you want the same action. For example you might have
switch(c) {
case 'd':
case 'D':
scanf("%d, &a); break;
/* etc */
}
This would allow the user to get the expected action regardless of the case of the letter they entered.
But you might want to consider what to do if the user inputs invalid data, for example what happens if they choose Octal then enter the number 99, or "Hello". Also, consider what happens if the user enters "octal" in response to the prompt for the base.