-
Background Help
I would like to add a background colour on my programme
Code:
#include <stdio.h>
#include<stdlib.h>
int menu();
int distance();
int sw;
int main()
{
menu();
float value;
value=distance();
printf("%f", value);
return 0;
}
int menu()
{
system("cls");
printf(" Please choose a category below\n");
printf(" 1.Weight\n");
printf(" 2.Measurement\n");
printf(" 3.Distance\n");
printf(" 4.Temperature \n ");
sw=getchar();
sw=sw-'0';
switch(sw)
{
case 1:
weight();
break;
case 2:
measurement();
break;
case 3:
distance();
break;
case 4:
temperature();
break;
case 5:
main();
break;
default:
menu();
break;
}
}
int weight()
{
system("cls");
printf(" Weight\n");
printf(" 1.Ounce to Pounds\n");
printf(" 2.Pounds to Ounce\n");
printf(" 3.Pounds to Kilograms\n");
printf(" 4.Kilograms to Pounds\n");
printf(" 5.Back to the Main menu\n");
sw=getchar();
sw=sw-'0';
switch(sw)
{
case 1:
OtoP();
break;
case 2:
PtoO();
break;
case 3:
PtoK();
break;
case 4:
KtoP();
break;
case 5:
main();
break;
default:
weight();
break;
}
}
int OtoP()
{
float oz,lb;
printf("\n\n");
printf("Enter Ounce: ");
scanf("%f",&oz);
lb=oz/16;
printf("\n\n");
printf("%f ounce = %f pounds",oz,lb);
getch();
return weight();
}
int PtoO()
{
float oz,lb;
printf("\n\n");
printf("Enter Pounds: ");
scanf("%f",&oz);
lb=oz*16;
printf("\n\n");
printf("%f Pounds = %f Ounce",oz,lb);
getch();
return weight();
}
int PtoK()
{
float kg,lb;
printf("\n\n");
printf("Enter Pounds: ");
scanf("%f",&kg);
lb=kg*0.453592;
printf("\n\n");
printf("%f Pounds = %f Kilograms",kg,lb);
getch();
return weight();
}
int KtoP()
{
float kg,lb;
printf("\n\n");
printf("Enter Kilograms: ");
scanf("%f",&kg);
lb=kg/0.453592;
printf("\n\n");
printf("%f Kilograms = %f Pounds",kg,lb);
getch();
return weight();
}
int measurement()
{
system("cls");
printf(" Measurement\n");
printf(" 1.Centimetres to Inches\n");
printf(" 2.Inches to Centimetres\n");
printf(" 3.Inches to Feet\n");
printf(" 4.Feet to Inches\n");
printf(" 5.Back to the Main menu\n");
sw=getchar();
sw=sw-'0';
switch(sw)
{
case 1:
CtoI();
break;
case 2:
ItoC();
break;
case 3:
ItoF();
break;
case 4:
FtoI();
break;
case 5:
main();
break;
default:
measurement();
break;
}
}
int CtoI()
{
float in,cm;
printf("\n\n");
printf("Enter Centimetres: ");
scanf("%f",&cm);
in=cm*0.3937;
printf("\n\n");
printf("%f Centimetres = %f Inches",cm,in);
getch();
return measurement();
}
int ItoC()
{
float in,cm;
printf("\n\n");
printf("Enter Inches: ");
scanf("%f",&cm);
in=cm/0.3937;
printf("\n\n");
printf("%f Inches = %f Centimetres",cm,in);
getch();
return measurement();
}
int ItoF()
{
float in,ft;
printf("\n\n");
printf("Enter Inches: ");
scanf("%f",&ft);
in=ft*0.083;
printf("\n\n");
printf("%f Inches = %f Foot",ft,in);
getch();
return measurement();
}
int FtoI()
{
float in,ft;
printf("\n\n");
printf("Enter Foot: ");
scanf("%f",&ft);
in=ft/0.083;
printf("\n\n");
printf("%f Foot = %f Inches",ft,in);
getch();
return measurement();
}
int distance()
{
system("cls");
printf(" Distance\n");
printf(" 1.Miles to kilometres\n");
printf(" 2.Kilomeres to miles\n");
printf(" 3.Back to the Main menu\n");
sw=getch();
sw=sw-'0';
switch(sw)
{
case 1:
MtoK();
break;
case 2:
KtoM();
break;
case 3:
main();
break;
default:
distance();
break;
}
}
int MtoK()
{
float k,m;
printf("\n\n");
printf("Enter miles: ");
scanf("%f",&m);
k=m*1.609344;
printf("\n\n");
printf("%f miles = %f kilometers",m,k);
getch();
return distance();
}
int KtoM()
{
float k,m;
printf("\n\n");
printf("Enter kilometres: ");
scanf("%f",&m);
k=m/1.609344;
printf("\n\n");
printf("%f kilometres = %f miles",m,k);
getch();
return distance();
}
int temperature()
{
system("cls");
printf(" Temperature\n");
printf(" 1.Fahrenheiht to Centigrade\n");
printf(" 2.Centigrade to Fahrenheiht\n");
printf(" 3.Kelvin to Fahrenheit\n");
printf(" 4.Kelvin to Centigrade\n");
printf(" 5.Back to Main Menu\n");
sw=getch();
sw=sw-'0';
switch(sw)
{
case 1:
FtoC();
break;
case 2:
CtoF();
break;
case 3:
KtoF();
break;
case 4:
KtoC();
break;
case 5:
main();
break;
default:
temperature();
break;
}
}
int FtoC()
{
float c,f;
printf("\n\n");
printf("Enter Fahrenheiht: ");
scanf("%f",&f);
c=(f-32)*5/9;
printf("\n\n");
printf("%f Fahrenheiht = %f Centigrade",f,c);
getch();
return temperature();
}
int CtoF()
{
float f,c;
printf("\n\n");
printf("Enter Centigrade: ");
scanf("%f",&c);
f=c*33.8;
printf("\n\n");
printf("%f Centigrade = %f Fahrenheiht",c,f);
getch();
return temperature();
}
int KtoF()
{
float f,k;
printf("\n\n");
printf("Enter Kelvin: ");
scanf("%f",&k);
f=((k-273.15)*1.8)+32;
printf("\n\n");
printf("%f Kelvin = %f Fahrenheit",k,f);
getch();
return temperature();
}
int KtoC()
{
float c,k;
printf("\n\n");
printf("Enter Kelvin: ");
scanf("%f",&k);
c=k-272.15;
printf("\n\n");
printf("%f Kelvin = %f Centigrade",k,c);
getch();
return temperature();
}
I want to have a blue background with white text
I know it proberly simple to do if some one can help me it would be a huge help :)
-
You could try the ncurses library. It's been ported to windows. I don't program under windows and haven't for quite some time really. If you're using Linux or another flavor of Unix with ANSI terminal emulation, then you should check out my post under "Dividing the Terminal" in the Linux section of the forums. I posted some simple ANSI macros which should work on any platform with ANSI terminal emulation. Windows does not use ANSI terminal emulation though, so they won't work under windows
ncurses is probably your best bet if you want to write portable code though that will run just as happily on Windows or Linux or whatever since it's been ported to every platform with a console/terminal environment
However, there are a set of console functions in the Platform SDK (or whatever they're calling it these days ) that handle things like setting colors on the screen. Below is a site that discusses changing foreground and background colors using the Platform SDK
Setting Windows Console Text Colors in C - Jim Lawless' Blog
Hope this helps! And no! To answer your question! There really is no "standard way" of setting text attributes on a given console/terminal... There are ANSI standards, Microsoft standards and common libraries found on various Operating Systems etc. But no single standard way...
**EDIT**
Accidentally posted a C# link before discussing the Microsoft functions you're looking for.. Replaced it with a C link
-
SourceForge.net: Indentation - cpwiki
Before you do anything, you need to make your code readable.