#include int band1; int band2; int band3; int tol; float resistor; int x; int tolerance; char colourcode [12][7] = {{"Black \0"}, {"Brown \0"}, {"Red \0"}, {"Orange\0"}, {"Yellow\0"}, {"Green \0"}, {"Blue \0"}, {"Violet\0"}, {"Grey \0"}, {"White \0"}, {"Silver\0"}, {"Gold \0"}}; //multidimensional array of colour bands int main(void) { printf("\n\nResistor colour code checker, copyright 2004 by T.M.Elner\n\n"); printf("1. Black \n2. Brown \n3. Red \n4. Orange\n5. Yellow \n6. Green \n7. Blue \n8. Violet\n9. Grey \n10. White \n11. Silver\n12. Gold \n\n"); printf("Please Enter the numbers corresponding to the colour\nbands seperated by a comma, enter a zero if a fourth band isn't present: \n\n"); scanf("%d,%d,%d,%d",&band1,&band2,&band3,&tol); if(band1>12 || band1<1){ printf("\n\nIncorrect Entry for Band 1, values between 1 and 12 only\n\n"); system("pause"); main(); } if(band2>12 || band2<1){ printf("\n\nIncorrect Entry for Band 2, values between 1 and 12 only\n\n"); system("pause"); main(); } if(band3>12 || band3<1){ printf("\n\nIncorrect Entry for Band 3, values between 1 and 12 only\n\n"); system("pause"); main(); } if(tol== 0 || tol==3 || tol==11 || tol==12){} else{ printf("\n\nIncorrect Entry for Tolerance, values 0, 3, 11 and 12 only\n\n"); system("pause"); system("cls"); main(); } band1--;band2--;band3--; //-1 because the array of colours start at 0, but the choice numbers start at 1 printf("\n\nYou have entered the following colour combination:\n\n"); printf("Band 1: %s\nBand 2: %s\nBand 3: %s\nTolerance: %s\n\n",colourcode[band1],colourcode[band2],colourcode[band3],colourcode[(tol-1)]); band1 = (band1 * 10); resistor = (band1 + band2); if(band3 == 11){resistor = resistor/10;} if(band3 == 10){resistor = resistor/100;} if(band3<10){ while(band3>0){ resistor = resistor * 10; band3--; } } if(tol == 12){tolerance = 5;}; if(tol == 11){tolerance = 10;}; if(tol == 3){tolerance = 2;}; if(tol == 0){tolerance = 20;}; printf("Resistor value is: \n\n"); if(resistor<1000){printf("%f ohms +/- %d %c\n\n",resistor, tolerance,37);} if(resistor>=1000 && resistor<1000000){printf("%f Kohms +/- %d %c\n\n",(resistor/1000), tolerance,37);} if(resistor>=1000000 && resistor<1000000000){printf("%f Mohms +/- %d %c\n\n",(resistor/1000000), tolerance,37);} system("pause"); system("cls"); main(); return 0; }