Try this - slightly rearranged...
#include <stdio.h>
#include <math.h>
#pragma comment(linker, "/SubSystem:Console")
#pragma warn(disable:2216) // retval never used
#pragma warn(disable:2215) // conversion ... loss of data
double decode_char( char code ) {
switch (code) {
case 'N':
return 0.0;
case 'B':
return 1.0;
case 'R':
return 2.0;
case 'O':
return 3.0;
case 'Y':
return 4.0;
case 'G':
return 5.0;
case 'I':
return 6.0;
case 'V':
return 7.0;
case 'E':
return 8.0;
case 'W':
return 9.0;
}
}
int main (void)
{
char code1, code2, code3, code4;
double band, resistance;
double color1, color2, color3, color4;
code1 = getchar();
code2 = getchar();
code3 = getchar();
code4 = getchar();
color1 = decode_char( code1 );
color2 = decode_char( code2 );
color3 = decode_char( code3 );
color4 = decode_char( code4 );
printf("Is the resistor 3 or 4 band? ");
scanf("%lf", &band);
if(band == 3) {
printf( "\n\n\tThe colored bands are coded as follows:\n\n\n\t" );
printf( "COLOR\t\t\tCODE\n\t" );
printf( "-----\t\t\t----\n\n" );
printf( "\tBlack___________________________> N\n" );
printf( "\tBrown___________________________> B\n" );
printf( "\tRed_____________________________> R\n" );
printf( "\tOrange__________________________> O\n" );
printf( "\tYellow__________________________> Y\n" );
printf( "\tGreen___________________________> G\n" );
printf( "\tBlue____________________________> I\n" );
printf( "\tViolet__________________________> V\n" );
printf( "\tGrey____________________________> E\n" );
printf( "\tWhite___________________________> W\n" );
printf( "\n\n\tEnter three colors with no spaces. ");
resistance = ( 10.0 * color1 + color2 )
* pow( 10.0, color3 );
printf("\n\n Resistance in ohms: %f", resistance);
}
if(band == 4) {
printf( "\n\n\tThe colored bands are coded as follows:\n\n\n\t" );
printf( "COLOR\t\t\t\tCODE\n\t" );
printf( "-----\t\t\t\t----\n\n" );
printf( "\tBlack___________________________> N\n" );
printf( "\tBrown___________________________> B\n" );
printf( "\tRed_____________________________> R\n" );
printf( "\tOrange__________________________> O\n" );
printf( "\tYellow__________________________> Y\n" );
printf( "\tGreen___________________________> G\n" );
printf( "\tBlue____________________________> I\n" );
printf( "\tViolet__________________________> V\n" );
printf( "\tGrey____________________________> E\n" );
printf( "\tWhite___________________________> W\n" );
printf( "\n\n\tEnter four colors with no spaces. ");
resistance = ( 10.0 * color1 + color2 + color3 )
* pow( 10.0, color4 );
printf("\n\n Resistance in ohms: %f", resistance);
}
return (0);
}