#include<stdio>
#include<iostream>
#include<conio>
/* 2 point form*/

float x1,x2,y1,y2;
cout << "\n Enter values in order x1,x2,y1,y2: ";

   cin>>x1>>x2>>y1>>y2;
   
   float slope;
   
   slope=(y2-y1)/(x2-x1);
   
   float c=y1-slope*x1;
   
   cout<<"\nThe equation of the line is : y="<<slope<<" x + "<<c<<endl;

Recommended Answers

All 21 Replies

you have to put all that code in a main() function

// includes go here

int main()
{
    // code goes here

   return 0;
}

thanks..its working now...can u tell me how to change the color of the background and text ?

>can u tell me how to change the color of the background and text ?
There's no standard way to do it, but because you seem to be using a Windows compiler, I'd say this is your best bet.

>#include<stdio>
Remove this, you're not using anything from stdio. Also, it's <cstdio>, not <stdio>.

>#include<conio>
Remove this, you're not using anything from conio. Also, it's <conio.h>, not <conio>.

And stop making multiple threads on the same stupid with the same stupid title. Please read the RULES.

commented: Yeah, you tell 'em! +12

Header conio.h has this function for working with text:

void textcolor(int Color);

"Color" can be:

BLACK
 BLUE
 GREEN
 CYAN
 RED
 MAGENTA
 BROWN
 LIGHTGRAY
 DARKGRAY
 LIGHTBLUE
 LIGHTGREEN
 LIGHTCYAN
 LIGHTRED
 LIGHTMAGENTA
 YELLOW
 WHITE

Also you can add a blink bit. For example:

textcolor(RED + BLINK);

Function which works with background:

void textbackground(int Color);

But background color can only be:

BLACK
 BLUE
 GREEN
 CYAN
 RED
 MAGENTA
 BROWN
 LIGHTGRAY

And the general function:

void textattr(int NewAttr);

NewAttr is 8-bit variable

Bbbbffff

Where B - blink bit
b - background bits
f - foreground bits

Alll this functions are declared in conio.h.
Hope you find this inf helpful!

>Header conio.h has this function for working with text:
Prove it. I can only think of one compiler vendor that supplies that particular function with their version of conio.h. All of the others would fail to compile code that uses it.

So look for this functions in YOUR compilers. I have all this under Borland and Visual platforms ALL VERSIONS. Also Dev C++ has this functions! Say which platform can't use this?? It would be intereting to me. )))

Forget to say: to display text use

cprintf(char* format, ...);
puttext(int x1, int y1, int x2, int y2, void*TextString);

It doesn't work with Code::Blocks. I think it works only in the old version of C compiler such as Turbo C.

So look for this functions in YOUR compilers. I have all this under Borland and Visual platforms ALL VERSIONS.

VC++ 6.0 -- no
VC++ 2005 Express -- No
VC++ 2008 Express -- No

They all have conio.h but none of them support textattr().

>I have all this under Borland and Visual platforms ALL VERSIONS.
BS. Since all I have to do is pick out one to prove you wrong, how about Visual Studio? textcolor isn't recognized, and a look into conio.h shows that it's not present. You'll find that to be consistent throughout the versions of Visual Studio. Before you lie make sure you're talking to someone stupid and gullible. I'm neither.

This is a quick and dirty implementation of the Microsoft API to change console color

enum Colors { 
blue=1, green, cyan, red, purple, yellow, grey, dgrey,
hblue, hgreen, hcyan, hred, hpurple, hyellow, hwhite }

void set_tcolor(short int a)
{
     HANDLE handle = GetStdHandle( STD_OUTPUT_HANDLE ); // Make a handle
     SetConsoleTextAttribute( handle, a ); // Set the color of the text
}
void coutc(int color, char* output, bool newline)
{
     set_tcolor(color);
     cout<< output;
     if(newline) cout << endl;
     set_tcolor(grey);
}
void coutc(int color, int output, bool newline)
{
     set_tcolor(color);
     cout<< output;
     if(newline) cout << endl;
     set_tcolor(grey);
}

>I have all this under Borland and Visual platforms ALL VERSIONS.
BS. Since all I have to do is pick out one to prove you wrong, how about Visual Studio? textcolor isn't recognized, and a look into conio.h shows that it's not present. You'll find that to be consistent throughout the versions of Visual Studio. Before you lie make sure you're talking to someone stupid and gullible. I'm neither.

OK not all visuals have it. I look through conio.h in Visual C++ v6.0, really standart it hasn't got these functions. I know why. Microsoft likes working with dynamic consoles, link to these functions you have posted before. You need to do different tricks to say Goodbye to dynamic consoles. Also Visual doesn't work with normal consoles AT ALL!
To invisal-> You are kidding. Borlan C++ Builder 6.0 is not the oldest and it's working with conio.h normally!

Similarly to ShawnCplus code:

void SetTextColor(WORD color)
{
   SetConsoleTextAttribute( 
         GetStdHandle(STD_OUTPUT_HANDLE),
         color);
}

To use this function, <windows.h> must be included and your program must run on Windows.
Here is the list of colours that are available.

* Black = 0
    * Red = RED
    * Green = GREEN
    * Blue = BLUE
    * Cyan = GREEN | BLUE
    * Magenta = RED | BLUE
    * Yellow = RED | GREEN
    * Dark Grey = RED | BLUE | GREEN
    * Light Grey = INTENSITY
    * Light Red = INTENSITY | RED
    * Light Green = INTENSITY | GREEN
    * Light Blue = INTENSITY | BLUE
    * Light Cyan = INTENSITY | GREEN | BLUE
    * Light Magenta = INTENSITY | RED | BLUE
    * Light Yellow = INTENSITY | RED | GREEN
    * White = INTENSITY | RED | BLUE | GREEN

In order to use this colour, you need to include its prefix. There are 2 prefix: FOREGROUND_ and BACKGROUND_.

Example:

// Set text colour to Red
SetTextColor(FOREGROUND_RED);
// Set text colour to White
SetTextColor(FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
// Set text colour to Red with Blue background
SetTextColor(FOREGROUND_RED | BACKGROUND_BLUE);

heh, forgot about that. But to use the functions just do

coutc(red, "How's everyone doing?", true);
coutc(green, 5000, false);

That will display
How are you doing?
5000

To invisal-> You are kidding. Borlan C++ Builder 6.0 is not the oldest and it's working with conio.h normally!

Borland C++ Builder 6.0 isn't old, but it use the old libraries from Turbo C.

Borland C++ Builder 6.0 isn't old, but it use the old libraries from Turbo C.

in contrast to Microsoft Visual C++ Borland is in principe: "Add, don't remove". :-) The file version in my Builder is 2002 year, so it is not so old.

conio.h works fine for me in Borland DevC++

conio.h works fine for me in Borland DevC++

I think you mean Bloodshed Dev-C++, anyway, I'd have to agree with AD and Narue. Everything I've ever learned has guided me away from conio.h.

>>Borland DevC++
Dev-C++ is not a Borland product.

>>OK not all visuals have it.
NONE OF THEM HAVE IT.

conio.h works fine for me in Borland DevC++

We were talking about the existen of textcolor in <conio.h>. Since DevC++ and Code::Blocks use gcc compiler, the result must be the same.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.