943,733 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 858
  • C RSS
Nov 4th, 2008
0

Would like to add color to my program.

Expand Post »
I have this except from my program and would like to change the line showing the error to say red, how would I do that?

switch (choice)
{
case 1:
{
printf("\nThank you for choosing the Del Mar Store");
printf("\nThe price you entered is: $%10.2f<<<<\n", (price));
printf("The Sales tax on that item is: $%10.2f<<<<\n", (DMPrice));
printf("Bringing your Total Sales to: $%10.2f<<<<\n", (DMTotal));
} break;
case 2:
{
printf("\nThank you for choosing the Encinitas Store");
printf("\nThe price you entered is: $%10.2f<<<<\n", (price));
printf("The Sales Tax on that item is: $%10.2f<<<<\n", (ENPrice));
printf("Bringing your Total Sales to: $%10.2f<<<<\n", (ENTotal));
} break;
case 3:
{
printf("\nThank you for choosing the LaJolla Store");
printf("\nThe price you entered is: $%10.2f<<<<\n", (price));
printf("The Sales Tax on that item is: $%10.2f<<<<\n", (LJPrice));
printf("Bringing your Total Sales to: $%10.2f<<<<\n", (LJTotal));
} break;
default:
//Used to let user know they made an invalid Store Choice.
printf("\nI am sorry that is not a valid choice!\n\n"); This is the line I would like to change to "red" so they know that they made a mistake.
}
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Trades is offline Offline
4 posts
since Nov 2008
Nov 4th, 2008
0

Re: Would like to add color to my program.

Are you printing this out to the command line?
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008
Nov 4th, 2008
0

Re: Would like to add color to my program.

I did some research. This looks like it's a giant pain in the butt. Here's a helpful thread if you're hell bent on some colors
http://gpwiki.org/forums/viewtopic.php?t=2884
Reputation Points: 10
Solved Threads: 6
Newbie Poster
bionicseraph is offline Offline
19 posts
since Nov 2008
Nov 5th, 2008
0

Re: Would like to add color to my program.

there are different colors associated in c
just write the color u want, above the text
for eg,
COLOR(RED);
these are all included in header file graphics.h
Reputation Points: 6
Solved Threads: 9
Junior Poster in Training
ajay.krish123 is offline Offline
90 posts
since Nov 2008
Nov 5th, 2008
0

Re: Would like to add color to my program.

hmm well i havnt done it in awhile but when i did i used this function
  1. void setcolor(unsigned short color)
  2. {
  3. HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  4. SetConsoleTextAttribute(hCon,color);
  5. }
if you loop through the colors like
  1. for(int i =0i<=255;i++)
  2. {
  3. setcolor(i);
  4. cout << i;
  5. }
Last edited by twek; Nov 5th, 2008 at 4:44 am.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
twek is offline Offline
8 posts
since Nov 2008
Nov 5th, 2008
0

Re: Would like to add color to my program.

Are you printing this out to the command line?
This is a program for school that asks the user for a dollar amount and then displays the tax and total sales for the price entered. I just want to have the different stores show up in different colors.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Trades is offline Offline
4 posts
since Nov 2008
Nov 5th, 2008
0

Re: Would like to add color to my program.

Tried as you suggested:

color(red);
printf("\nI am sorry that is not a valid choice!\n\n");

What I get is an error that says cannot find variable "red"
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Trades is offline Offline
4 posts
since Nov 2008
Nov 5th, 2008
0

Re: Would like to add color to my program.

Did I say the school is using Miracle C compiler. Version 3.2, I know this might be older but it is what I have to work with.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Trades is offline Offline
4 posts
since Nov 2008
Nov 5th, 2008
0

Re: Would like to add color to my program.

Click to Expand / Collapse  Quote originally posted by Trades ...
Tried as you suggested:

color(red);
printf("\nI am sorry that is not a valid choice!\n\n");

What I get is an error that says cannot find variable "red"
did you try my suggestion?
here ill include an example for you,
please let me know if it works
Attached Files
File Type: cpp prettyColors.cpp (392 Bytes, 35 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
twek is offline Offline
8 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: C programming
Next Thread in C Forum Timeline: Sine Series





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC