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.
}

Edited 3 Years Ago by happygeek: fixed formatting

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

hmm well i havnt done it in awhile but when i did i used this function

void setcolor(unsigned short color)                
{                                                   
    HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hCon,color);
}

if you loop through the colors like

for(int i =0i<=255;i++)
{
setcolor(i);
cout << i;
}

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.

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 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.

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

Attachments
#include <stdio.h>
#include <windows.h>
#include <stdlib.h>
void setcolor(unsigned short color)                
{                                                   
    HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hCon,color);
}

int main()
{
	for(int i = 0;i<=255;i++)
	{
		setcolor(i);
		printf("this color is :%d\n",i);
	}
	system("pause");
}
This article has been dead for over six months. Start a new discussion instead.