i have a homework assignment in which i am supposed to find the nominal value of a fixed resistor, given the resistor's color code. each color code has a corresponding letter and i need to make a user defined function that converts that letter to a number. the numbers for the color codes are as follows:
0 - B(Black)
1 - N(Brown)
2 - R(Red)
3 - O(Orange)
4 - Y(Yellow)
5 - G(Green)
6 - L(Blue)
7 - V(Violet)
8 - A(Gray)
9 - W(White)
-1 - D(Gold)
-2 - S(Silver)
so far i have written this much code
Code:
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(){
int dig1,dig2,dig3;
printf("These are the color choices you have: \nBlack-B\nBrown-N\nRed-R\nOrange-O\nYellow-Y\nGreen-G\nBlue-L\nViolet-V\nGray-A\nWhite-W\nGold-D\nSilver-S\n");
printf("Enter first color->");
scanf("%d",&dig1);
printf("Enter second color->");
scanf("%d",&dig2);
printf("Enter third color->");
scanf("%d",&dig3);
float
nom=((10*dig1)+dig2)*pow(10,dig3);
printf("The nominal resistance is %f",nom);
getch();
return 0;
}
i still need the user defined function to convert the color code letters to the numbers but i have no idea what to do! please help someone!