# Resistor color code (Takes in numeric values and prints color)

Page 1 of 1

## 14 Replies - 8548 Views - Last Post: 09 July 2012 - 07:51 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=284912&amp;s=c590a16e48bbc28f186dd4502ca5ad65&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Ricardo1118

Reputation: 0
• Posts: 7
• Joined: 05-July 12

# Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 12:18 AM

SALAM,

I AM BEGINNER AT C PROGRAMMING AND I AM WILLING TO MAKE A C PROGRAM FOR RESISTOR COLOUR CODING. I HAVE MADE A PROGRAM WHICH TAKES IN NUMERICAL VALUE AND GIVES OUTPUT COLOUR BANDS IN STRINGS.

BUT I NEED THAT INSTEAD OF SHOWING COLOURS IN STRINGS. IT SHOW THE COLOUR BANDS IN GRAPHICS.

I KNOW NOTHING MUCH ABOUT GRAPHICS.

THE PROGRAM I MADE IS GIVEN:
KINDLY COMPLETE THIS PROGRAM FOR GRAPHICS INSTEAD OF COLOUR STRINGS.

/*This program takes input of resistance in digits and prints
/*colour bands in a string*/

void main ()
{
char x,y;
int z,count=-1;
clrscr();
printf("enter tolerance (5 or 10 or  20):");
scanf("%d", &z);
printf("enter resistance value:");
x=getche();                       /*takes first digit*/
y=getche();                       /*takes second digit*/
while(getche()!='\r')             /*takes number of zeros*/
count++;
clrscr();
switch (x)                        /*colour band for first digit*/
{
case '0':
printf("black   ");
break;
case '1':
printf("brown   ");
break;
case '2':
printf("red   ");
break;
case '3':
printf("orange   ");
break;
case '4':
printf("yellow   ");
break;
case '5':

printf("green   ");
break;
case '6':
printf("blue   ");
break;
case '7':
printf("violet   ");
break;
case '8':
printf("grey   ");
break;
case '9':
printf("white   ");
break;
default:
printf("unknown value   ");
}
switch (y)                                   /*colour band for second digit*/
{
case '0':
printf("black   ");
break;
case '1':
printf("brown   ");
break;
case '2':
printf("red   ");
break;
case '3':
printf("orange   ");
break;
case '4':
printf("yellow   ");
break;
case '5':
printf("green   ");
break;
case '6':
printf("blue   ");
break;
case '7':
printf("violet   ");
break;
case '8':
printf("grey   ");
break;
case '9':
printf("white   ");
break;
default:
printf("unknown value   ");
}
switch (count)                     /*colour band for number of zeros*/
{
case 0:
printf("black   ");
break;
case 1:
printf("brown   ");
break;
case 2:
printf("red   ");
break;
case 3:
printf("orange   ");
break;
case 4:
printf("yellow   ");
break;
case 5:
printf("green   ");
break;
case 6:
printf("blue   ");
break;
case 7:
printf("violet   ");
break;
case 8:
printf("grey   ");
break;
case 9:
printf("white   ");
break;
default:
printf("unknown value   ");
}
switch (z)
{                                                 /*colour band for tolerance*/
case 5:
printf("gold");
break;
case 10:
printf("silver");
break;
case 20:
printf("no colour");
break;
default:
printf("unknown value");
break;
}
getch();
}

This post has been edited by Salem_c: 06 July 2012 - 12:49 AM
Reason for edit:: Added [code][/code] tags - learn to use them yourself

Is This A Good Question/Topic? 0

## Replies To: Resistor color code (Takes in numeric values and prints color)

### #2 Salem_c

• void main'ers are DOOMED

Reputation: 2140
• Posts: 4,206
• Joined: 30-May 10

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 12:55 AM

First, don't go round shouting (all CAPS)
http://www.catb.org/....html#writewell

Second, don't spam the net with your question.
http://forums.anandt....php?p=33657360
http://www.catb.org/...ions.html#forum

Third, if you want graphics, then you're going to have to tell us which operating system and compiler(*) you're using. Standard C knows nothing about graphics, it all depends on your platform.
And try to be more specific than say "Windows" or "Borland".

(*)though I rather suspect TurboC is about to be mentioned.....)

### #3 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 01:12 AM

Yup, I also think TC++ is involved. I am surprised you did not mention the void main().

### #4 busyme12srv

Reputation: -5
• Posts: 44
• Joined: 18-June 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 02:03 AM

You have to read the topics on <graphics.h> header file, and about graphic functions in Turbo C++

### #5 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 02:37 AM

Let me stop you right now. graphics.h is a non-standard header file, found only in TC++. Use a proper compiler like code::blocks or Microsoft Visual C++, which are modern. From there, you can use proper libraries like ncurses or windows.h to add graphics to your program.

### #6 Ricardo1118

Reputation: 0
• Posts: 7
• Joined: 05-July 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 05:19 AM

Salem_c, on 06 July 2012 - 12:55 AM, said:

First, don't go round shouting (all CAPS)
http://www.catb.org/....html#writewell

Second, don't spam the net with your question.
http://forums.anandt....php?p=33657360
http://www.catb.org/...ions.html#forum

Third, if you want graphics, then you're going to have to tell us which operating system and compiler(*) you're using. Standard C knows nothing about graphics, it all depends on your platform.
And try to be more specific than say "Windows" or "Borland".

(*)though I rather suspect TurboC is about to be mentioned.....)

### #7 Ricardo1118

Reputation: 0
• Posts: 7
• Joined: 05-July 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 05:27 AM

First I copy pasted my question which i written in wordpad in all caps

Secondly, I have posted my post to these two forums because i need some quick reply.

Third I am using Borland Turbo C.
If it dosen't support all colours then give me the approximate colours

### #8 Ricardo1118

Reputation: 0
• Posts: 7
• Joined: 05-July 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 05:34 AM

busyme12srv, on 06 July 2012 - 02:03 AM, said:

You have to read the topics on <graphics.h> header file, and about graphic functions in Turbo C++

does <graphics.h> also works on borland turbo C compiler

### #9 jimblumberg

Reputation: 5444
• Posts: 16,968
• Joined: 25-December 09

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 05:53 AM

POPULAR

Quote

First I copy pasted my question which i written in wordpad in all caps

So don't write it in all caps. What difference does it make that you cut and pasted from wordpad? Wordpad doesn't force you to use all caps, does it?

Quote

Secondly, I have posted my post to these two forums because i need some quick reply.

Posting all over the internet doesn't mean you will get a quick reply. It just means that you think you are the center of the universe. Pick one forum. Don't be rude.

Quote

Third I am using Borland Turbo C.
If it dosen't support all colours then give me the approximate colours

That's a shame. This is one of if not the most outdated compilers available and you should find a compiler that was at least developed in this century.

Quote

Proper communication is a vital skill for a programmer. Learn to properly communicate and people will not criticize you.

Quote

does <graphics.h> also works on borland turbo C compiler

No, <graphics.h> is only supported by the outdated Borland Turbo-C/C++ compilers.

You really should come into this century and download a modern compiler and use a modern graphics package. You may want to investigate one of the many free to download compilers like Code::Blocks, wxDev-C++, Visual C++. Then you could use one of the many modern graphics programs like, openGL, Allegro, and many more.

Edit:

Quote

THE PROGRAM I MADE IS GIVEN:
KINDLY COMPLETE THIS PROGRAM FOR GRAPHICS INSTEAD OF COLOUR STRINGS.

No, that is your job. We are not a code writing service.

Jim

This post has been edited by jimblumberg: 06 July 2012 - 06:02 AM

### #10 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 07:22 AM

I tend to agree with Jim.

### #11 #define

• Duke of Err

Reputation: 1853
• Posts: 6,671
• Joined: 19-February 09

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 09:08 PM

Instead of using graphics, you could try using the extended characters such as ▐ (value 222) and the textcolor() and cprintf() functions.

aresh, on 06 July 2012 - 12:37 PM, said:

Let me stop you right now. graphics.h is a non-standard header file, ... you can use proper libraries like ncurses or windows.h to add graphics to your program.

graphics.h, ncurses and windows.h are all non-standard header files/libraries.

aresh, on 06 July 2012 - 12:37 PM, said:

... graphics.h is ..., found only in TC++.

According to DIC FAQ's also found in Borland C++ 5.5.

aresh, on 06 July 2012 - 12:37 PM, said:

Use a proper compiler like code::blocks or Microsoft Visual C++, which are modern.

It is a proper compiler, perhaps you mean newer or better.

busyme12srv, on 06 July 2012 - 12:03 PM, said:

You have to read the topics on <graphics.h> header file, and about graphic functions in Turbo C++

Seems slight to get a negative rep for this.

Moral: mention TC or older compilers and get mobbed and no help - best to lie.

### #12 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 06 July 2012 - 10:20 PM

Yup, ncurses.h and windows.h are non-standard, but at least they are supported by most of the compliers. graphics.h is supported by TC++ and Borland C++ 5.5 (as if I care, #define). So the basic point of my argument was, don't even mention graphics.h.

### #13 Ricardo1118

Reputation: 0
• Posts: 7
• Joined: 05-July 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 07 July 2012 - 02:09 AM

*** Edit ***
Removed your reply that was just a quote of post #11 Was there supposed to be a reply or just wanted to quote something?

This post has been edited by GunnerInc: 07 July 2012 - 07:52 AM
Reason for edit:: Removed Quote

### #14 busyme12srv

Reputation: -5
• Posts: 44
• Joined: 18-June 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 09 July 2012 - 04:26 AM

aresh, on 06 July 2012 - 03:07 PM, said:

Let me stop you right now. graphics.h is a non-standard header file, found only in TC++. Use a proper compiler like code::blocks or Microsoft Visual C++, which are modern. From there, you can use proper libraries like ncurses or windows.h to add graphics to your program.

There is absolutely nothing wrong with <graphics.h> in Borland TC++. It is quite a good environment for medium scale graphics programming in MSDOS environment .

Of course ,for the 'resistor code program' stated above, even conio.h based color functions would do. <conio.h> is for console i/o functions like clrscr(), textcolor() functions in TC++ , in MSDOS environment.

ncurses.h is in Unix based compilers.

### #15 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Resistor color code (Takes in numeric values and prints color)

Posted 09 July 2012 - 07:51 AM

Fine, nothing is wrong with graphics.h. Agreed. I have also made many games with it. But, it is non-standard, and the OP will first learn graphics.h on your recommendation, and then for practical purposes he will have to learn some other library. After all, which company uses TC++ to produce programs ?? So it is better he learns some proper graphics library, or uses other functions like cprintf.