pls help me make a program that will input the color codes of a resistor and output the resistance using devc++ as a compiler..
First you need to prompt the user to enter the colours. Does the number of colours vary? If so will you account for this in your program?
Having entered the colours the program then needs to determine what those colours mean numerically. How you do this will depend on the way you make the user enter the colours: you could be cheeky and in effect make them do the conversion:
What is the first stripe? Enter 0 for black, 1 for brown, 2 for red (etc)
What is the second stripe? Enter 0 for black, (etc)
0: black 1: brown 2: red (etc)
Please enter the digits for the colours (e.g. for brown black red gold enter 102G):
(this is also better from a users point of view because if they have a lot of resistors to convert then (a) they will have less typing to do, (b) they will have less frustration because of typos ("sorry, don't recognise "blcak" - please re-enter" *), and (c) this will get them familiar with the numbers so that they won't need to rely on a program)
* although a neat trick would be to anticipate some possible typos and convert them automatically:
You will also need to determine if they entered the colours the wrong way. For example gold red black brown is a 1K resistor: they may not know that gold is the last stripe.
Then you will need to convert the resulting string into a number. Suppose you have "102G", then the first two digits are just converted as digits, and the 3rd digit is the multiplier, so this is (1+0*10)*100=1000 and the last stripe can be converted with a simple switch into the relevant percentage.
|All times are GMT +5.5. The time now is 08:25.|