A resistor is a circuit device designed to have a specific resistance value between its ends.
Resistance values are expressed in ohms (Ω). Resistors are frequently marked with colored
bands that encode their resistance values, as shown in the following figure. The first two bands
are digits and the third is a power-of-ten multiplier.
The table below shows the meanings of each band color. For example, if the first band
is green, the second is black, and the third is orange, the resistor has a value of 50×103
Ω.
Write a program that prompts for the colors of Band 1, Band 2 and Band 3, and then
displays the resistance in ohms. Here is a sample run:
Enter the colors of the resistor’s three bands, beginning
with the band nearest the end. Type the colors in lowercase
letters only, NO CAPS
Band 1 => green
Band 2 => black
Band 3 => yellow
Resistance value: 500 000 -ohms
Do you want to decode another resistor (Y/N)?
=> Y
Enter the colors of the resistor’s three bands, beginning
with the band nearest the end. Type the colors in lowercase
letters only, NO CAPS
Band 1 => red
Band 2 => orange
Band 3 => green
Resistance value: 2 300 000 –ohms
Do you want to decode another resistor (Y/N)?
=> Y
Enter the colors of the resistor’s three bands, beginning
with the band nearest the end. Type the colors in lowercase
letters only, NO CAPS.
Band 1 => brown
Band 2 => vilet
Band 3 => red
Invalid color: vilet
Do you want to decode another resistor (Y/N)?
=> Y
Enter the colors of the resistor’s three bands, beginning
with the band nearest the end. Type the colors in lowercase
letters only, NO CAPS.
Band 1 => brown
Band 2 => vilet
Band 3 => read
Invalid colors: vilet, read
Do you want to decode another resistor (Y/N)?
=> Y
Enter the colors of the resistor’s three bands, beginning
with the band nearest the end. Type the colors in lowercase
letters only, NO CAPS.
Band 1 => pink
Band 2 => silver
Band 3 => red
Invalid colors: pink, silver
Do you want to decode another resistor (Y/N)?
=> N
There are the color codes for resistors
Color Value as digit Value as multiplier
Black 0 1
Brown 1 10
Red 2 102
Orange 3 103
Yellow 4 104
Green 5 105
Blue 6 106
Violet 7 107
Grey 8 108
White 9 109