/* -------------------------------------------------------------------- ** Figure 6.24: Using a switch. ** -------------------------------------------------------------------- */ #include "tools.h" #define MAXDROP 5.0 /* volts */ void main( void ) { int gauge; /* selected gauge of wire */ float rho; /* resistivity of selected gauge of wire */ float amps; /* current rating of appliance */ float wlen; /* length of wire needed */ float drop; /* voltage drop for selected parameters */ banner(); puts( "\n Wire Gauge Adequacy Evaluation" ); printf( "\n Please choose gauge of wire:\n" "\t 12 gauge \n\t 14 gauge \n" "\t 16 gauge \n\t 18 gauge \n" " Enter selected gauge: " ); scanf( "%i", &gauge ); switch (gauge) { case 12: rho = 5.211; break; case 14: rho = 8.285; break; case 16: rho = 13.17; break; case 18: rho = 20.95; break; default: fatal( " Gauge %i is not supported.", gauge ); } printf( "\n Enter the current rating for the appliance, in amps: " ); scanf ( "%g", &s ); printf( "\n Enter the length of the wire, in meters: " ); scanf ( "%g", &wlen ); drop = 2 * wlen / 1000 * rho * amps ; printf( "\n For %i gauge wire %g meters long and %g amp appliance,\n" " voltage drop in wire = %g volts. (Limit is %g volts.) \n", gauge, wlen, amps, drop, MAXDROP ); if (drop < MAXDROP) printf( "\n Selected gauge is adequate.\n" ); else printf( "\n Selected gauge is not adequate.\n" ); bye(); }