14 Replies - 3576 Views - Last Post: 09 July 2012 - 07:51 AM Rate Topic: -----

#1 Ricardo1118  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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  Icon User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 1621
  • View blog
  • Posts: 3,078
  • 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.....)
Was This Post Helpful? 0
  • +
  • -

#3 aresh  Icon User is online

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • 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().
Was This Post Helpful? 0
  • +
  • -

#4 busyme12srv  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • 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++
Was This Post Helpful? 0
  • +
  • -

#5 aresh  Icon User is online

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • 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.
Was This Post Helpful? 1
  • +
  • -

#6 Ricardo1118  Icon User is offline

  • New D.I.C Head

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

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

Posted 06 July 2012 - 05:19 AM

View PostSalem_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.....)

Was This Post Helpful? 0
  • +
  • -

#7 Ricardo1118  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

And fourth please reply for my answer and kindly, not criticize method of my writing
Was This Post Helpful? 0
  • +
  • -

#8 Ricardo1118  Icon User is offline

  • New D.I.C Head

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

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

Posted 06 July 2012 - 05:34 AM

View Postbusyme12srv, 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
Was This Post Helpful? 0
  • +
  • -

#9 jimblumberg  Icon User is online

  • member icon


Reputation: 3987
  • View blog
  • Posts: 12,298
  • 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

And fourth please reply for my answer and kindly, not criticize method of my writing

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

Was This Post Helpful? 5
  • +
  • -

#10 aresh  Icon User is online

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • 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.
Was This Post Helpful? 0
  • +
  • -

#11 #define  Icon User is offline

  • Duke of Err
  • member icon

Reputation: 1302
  • View blog
  • Posts: 4,484
  • 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.


View Postaresh, 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.


View Postaresh, 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.


View Postaresh, 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.


View Postbusyme12srv, 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. :look:
Was This Post Helpful? 2
  • +
  • -

#12 aresh  Icon User is online

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • 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.
Was This Post Helpful? 0
  • +
  • -

#13 Ricardo1118  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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

Was This Post Helpful? 0
  • +
  • -

#14 busyme12srv  Icon User is offline

  • New D.I.C Head

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

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

Posted 09 July 2012 - 04:26 AM

View Postaresh, 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.
Was This Post Helpful? 0
  • +
  • -

#15 aresh  Icon User is online

  • It's a 16-Bit World!
  • member icon

Reputation: 273
  • View blog
  • Posts: 4,163
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1