Author Topic: Somewhat off topic.... I need help  (Read 1750 times)

0 Members and 1 Guest are viewing this topic.

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic.... I need help
I've been learning how to write C++ code and I was testing some of the functions in the conio.h header file. I wrote this code to test the textcolor() function but it won't compile.

Code:
#include
#include

int main()
{
  int i = 0;
  while(!i)
  {
    textcolor(15);
    cout << "\nTest\n";
    cin >> i;
  }
  return 0;
}

Error:
 
[Linker error] undefined reference to `textcolor'

I would appreciate it if someone who had expiereince in writing C++ could help me out.
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D

 

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic.... I need help
*bump*
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D

 

Offline Liberator

  • Poe's Law In Action
  • 210
Somewhat off topic.... I need help
Probably want to check in a programmers forum.

Buuuuuuuuutttttt......

check your spelling
check your text to make sure that the referenced command is in the included header files
so forth and so on

btw

How advanced are you?

My backwoods college didn't teach bupkis about including other .h files beside iostream and math and we really didn't learn all that much about math.h, suppose that's what I get for attending a community college in North Alabama.  The average tech level for the surrounding environs is about 35% of what you'd expect in a what is essentially a running rural suburb from Gadsden, AL to Huntsville, AL.
So as through a glass, and darkly
The age long strife I see
Where I fought in many guises,
Many names, but always me.

There are only 10 types of people in the world , those that understand binary and those that don't.

 

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic.... I need help
This is probably the most advanced thing that I have programmed so far... and its not very advanced yet but I've only been programming for about 2 weeks now.

typedef unsigned long int ULONG;
typedef unsigned short int USHORT;
#include

enum BOOL { FALSE , TRUE };
enum CHOICE { DrawRect = 1 , GetDims , GetArea , GetPerim,
               ChangeDims , Quit };
               
class Rectangle
{
  public:
    //Rectangle Constructor
    Rectangle( USHORT width , USHORT height );
    //Rectangle Deconstructor
    ~Rectangle();
    //accessors
    void setSize( USHORT newWidth , USHORT newHeight );
    USHORT getHeight() const { return itsHeight; }
    USHORT getWidth() const { return itsWidth; }
    ULONG getArea() const { return itsWidth * itsHeight; }
    ULONG getPerim() const { return 2*itsWidth + 2*itsHeight; }
  private:
    USHORT itsWidth;
    USHORT itsHeight;
};

//Rectangle Constructor
Rectangle::Rectangle( USHORT width , USHORT height )
{
  itsWidth = width;
  itsHeight = height;
}

//Rectangle Deconstructor
Rectangle::~Rectangle() {}

//Set the rectangle's size
void Rectangle::setSize( USHORT newWidth , USHORT newHeight )
{
  itsWidth = newWidth;
  itsHeight = newHeight;
}

USHORT menu();
void doGetArea( Rectangle );
void doGetPerim( Rectangle );
void doDrawRect( Rectangle );
void doGetDims( Rectangle );

int main()
{
  Rectangle theRect(10,10);
  USHORT choice = DrawRect;
  USHORT qQuit = FALSE;
  USHORT newHeight, newWidth;
  //Loop
  while (!qQuit)//While Quit is not true (or not equal to 1)
  {
    choice = menu();//Call the menu function
    if (choice < DrawRect || choice >  Quit)//Check to see if choice
                                            //is valid
    {
       cout << "\nInvalid Choice, please try again.\n\n";
       continue;
    }
    switch( choice )//Menu choices, default set to exit
    {
      case DrawRect:
        doDrawRect(theRect);
        break;
      case GetDims:
        doGetDims(theRect);
        break;
      case GetArea:
        doGetArea(theRect);
        break;
      case GetPerim:
        doGetPerim(theRect);
        break;
      case ChangeDims:
        cout << "\nEnter new height: ";
        cin >> newHeight;
        cout << "\nEnter new width: ";
        cin >> newWidth;
        theRect.setSize( newWidth , newHeight );
        cout << "\n";
        break;
      case Quit:
        qQuit = TRUE;
        break;
      default:
        cout << "Error in choice!\n";
        qQuit = TRUE;
        break;
    }//End switch
  }// End loop
}// End main

//Menu
USHORT menu()
{
  USHORT choice;
  cout << "--- Menu --- \n";
  cout << "(1) Draw Rectangle\n";
  cout << "(2) Dimensions\n";
  cout << "(3) Area\n";
  cout << "(4) Perimeter\n";
  cout << "(5) Resize\n";
  cout << "(6) Quit\n";
  cout << "\nChoice: ";
  cin >> choice;
  return choice;
}

//Draw the rectangle
void doDrawRect( Rectangle theRect )
{
  USHORT width = theRect.getWidth(); //Get rectangle width
  USHORT height = theRect.getHeight(); //Get rectangle height
  cout << "\n\n";
  for( USHORT i = 0; i < height; i++ )
  {
    for( USHORT j = 0; j < width; j++ )
      cout <<"*"; //draw *s until j is equal to the width
    cout <<"\n"; //draw another row of *s until i is equal to the height
  }
  cout << "\n\n";
}

//Get and output the area of the rectangle
void doGetArea( Rectangle theRect )
{
  ULONG area = theRect.getArea();
  cout << "\nArea: " << area << "\n\n";
}

//Get and output the perimeter of the rectangle
void doGetPerim( Rectangle theRect )
{
  ULONG perim = theRect.getPerim();
  cout << "\nPerimeter: " << perim << "\n\n";
}

//Get and output the dimensions of the rectangle
void doGetDims( Rectangle theRect )
{
  USHORT width = theRect.getWidth();
  USHORT height = theRect.getHeight();
  cout << "\nDimensions: ";
  cout << "\nWidth: " << width;
  cout << "\nHeight: " << height << "\n\n";
}
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D

 

Offline Tiara

  • Mrs. T, foo'!
  • 210
Somewhat off topic.... I need help
Code tags are your friends! :p
I AM GOD! AND I SHALL SMITE THEE!



...because I can :drevil:

 
Re: Somewhat off topic.... I need help
Quote
Originally posted by untouchable
I've been learning how to write C++ code and I was testing some of the functions in the conio.h header file. I wrote this code to test the textcolor() function but it won't compile.

Code:
#include
#include

int main()
{
  int i = 0;
  while(!i)
  {
    textcolor(15);
    cout << "\nTest\n";
    cin >> i;
  }
  return 0;
}

Error:
 
[Linker error] undefined reference to `textcolor'

I would appreciate it if someone who had expiereince in writing C++ could help me out.


If I remember right, textcolor() is not a standard function of conio.h. Are you sure that the conio.h you're using even has it? Atleast DJGPP has it, but I'm not sure about other compilers.

 

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic.... I need help
I examined the conio.h file and it included the function void textcolor(int color) and in the conio.c file was included the function definition:

void
textcolor (int color)
{
    __FOREGROUND = color;
    SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
      color + (__BACKGROUND << 4));
}
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D

 

Offline untouchable

  • Fear the DA...
  • 28
    • http://www.3dap.com/hlp/hosted/da
Somewhat off topic.... I need help
Ok... got it. I had to include the conio.c file as well as the header file for conio:
#include "conio.c"
"The Darkness shall  befall us all."
-Commander William Wright

"Violence is merely the means of the incompotent"
-Felix Steighner
----------------------
The Darkness is Coming


Untouchable has spoken :D

  
Somewhat off topic.... I need help
If you need programming tutorials, then I would highly advice you to visit this website: GameTutorials. You will find there dozens of C/C++/OpenGL/SDL/DirectX tuts for beginners and experts fellows. I have learnt a lot studying them  ;)