Borland...

This is a discussion on Borland... within the C++ Programming forums, part of the General Programming Boards category; I just bought Borland C++ 5.02 and it took me foever to figure out how to compile and run a ...

  1. #1
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200

    Borland...

    I just bought Borland C++ 5.02 and it took me foever to figure out how to compile and run a simple program. I cant figure ou how to use graphics.h and kbhit()...

    Ive used examples ive found in the forums but they will not work and call a warning about converting char to int.
    What is C++?

  2. #2
    Registered User Dual-Catfish's Avatar
    Join Date
    Sep 2001
    Posts
    802
    Do you have a question? I sure don't see one

  3. #3
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    ok....

    Why wont kbhit() work...

    Code:
    #include <iostream.h>
    #include <conio.h>
    
    char grid[3][3] = {
    {'*','*','*'},
    {'*','*','*'},
    {'*','*','*'}};
    
    char key;
    
    int x;
    int y;
    int count = 0;
    
    char changex;
    char changey;
    
    void makegrid();
    void plyrmve();
    
    void change_grid(const char changex, const char changey);
    
    int main()
    {
    
    	grid[0][0] = 'X';
    
    	for(count = 0; count < 9; count++){
       	   makegrid();
                    plyrmve();
                    clrscr();
                   }
    
       getch();
       return 0;
    
    }
    
    void makegrid()
    {
    	cout<<grid[0][0]<<grid[0][1]<<grid[0][2]<<endl
                 <<grid[1][0]<<grid[1][1]<<grid[1][2]<<endl
                 <<grid[2][0]<<grid[2][1]<<grid[2][2]<<endl;
    }
    
    void change_grid(const char changex, const char changey)
    {
       grid[x][y] = ' ';
    
       if ( changex == '+' )      x++;
       else if ( changex == '-')  x--;
       else if ( changey == '+')  y++;
       else if ( changey == '-')  y--;
       grid[x][y] = 'X';
    }
    
    void plyrmve()
    {
    
       	if ( kbhit() ){
    
    
                           key = getch();
    
    
       		switch( key )
          	{
          		case 72: change_grid ( '-', 0 ); break;
             	             case 80: change_grid ( '+', 0 ); break;
             	             case 75: change_grid ( 0, '-' ); break;
             	             case 77: change_grid ( 0, '+' ); break;
    
             	             default: cout<<"Error";
          	}
         }
    }
    it says may lose significant digits...
    Last edited by Vicious; 05-24-2002 at 11:58 PM.
    What is C++?

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Bah... Stupid code blocks wont align it right so... sorry for the sloppiness.
    What is C++?

  5. #5
    Registered User
    Join Date
    May 2002
    Posts
    317
    I believe it is because your change_grid function is prototyped to take char and in your switch statement you are passing an integer as an argument. The compiler is letting you know that when it does the type cast you may lose some accuracy, this isn't a problem in your case however and the warning shouldn't stop you from compiling and linking the program.

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    when I compile it and run it it just goes to the getch() func and doesnt even make the grid.
    What is C++?

  7. #7
    Registered User
    Join Date
    May 2002
    Posts
    317
    Are you sure, because according to your code it will cycle throw the for loop, clearing the screen each time, it never seems to wait for the user to press a key. Yes it does check for it, but it doesn;t wait for it. Then the last thing the for loop does is clear the screen before going to the getch() function........

  8. #8
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    oh i see...

    What header do i need for pause_for_input?
    would that stall it?
    What is C++?

  9. #9
    Registered User
    Join Date
    May 2002
    Posts
    317
    Just put a while statement in your plyrmve() function like this:
    Code:
                 while(!kbhit());
                  //then rest of code minus if statement

  10. #10
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    sigh...

    Well if i press anything now... it just closes

    Code:
    #include <iostream.h>
    #include <conio.h>
    #include <time.h>
    
    char grid[3][3] = {
    {'*','*','*'},
    {'*','*','*'},
    {'*','*','*'}};
    
    char key;
    
    int x;
    int y;
    int count = 0;
    
    char changex;
    char changey;
    
    void makegrid();
    void plyrmve();
    
    void change_grid(const char changex, const char changey);
    
    int main()
    {
    
    	grid[0][0] = 'X';
    
    	for(count = 0; count < 9; count++){
       	makegrid();
          plyrmve();
          clrscr();
          }
       getch();
       return 0;
    
    }
    
    void makegrid()
    {
    	cout<<grid[0][0]<<grid[0][1]<<grid[0][2]<<endl
       <<grid[1][0]<<grid[1][1]<<grid[1][2]<<endl
       <<grid[2][0]<<grid[2][1]<<grid[2][2]<<endl;
    }
    
    void change_grid(const char changex, const char changey)
    {
    	grid[x][y] = ' ';
       if ( changex == '+' )      x++;
       else if ( changex == '-')  x--;
       else if ( changey == '+')  y++;
       else if ( changey == '-')  y--;
       grid[x][y] = 'X';
    }
    
    void plyrmve()
    {
    
        while( !kbhit() ){
    
    
             key = getch();
    
    
       		switch( key )
          	{
          		case 72: change_grid ( '-', 0 ); break;
             	case 80: change_grid ( '+', 0 ); break;
             	case 75: change_grid ( 0, '-' ); break;
             	case 77: change_grid ( 0, '+' ); break;
    
             	default: cout<<"Error";
          	}
         }
    }
    What is C++?

  11. #11
    Registered User
    Join Date
    May 2002
    Posts
    317
    I'm sorry you must have misunderstood me. the code should be like this:
    Code:
     while(!kbhit()); //wait for key press
     
     key = getch();//when key is pressed continue with code
    
    
       		switch( key )
          	{
          		case 72: change_grid ( '-', 0 ); break;
             	case 80: change_grid ( '+', 0 ); break;
             	case 75: change_grid ( 0, '-' ); break;
             	case 77: change_grid ( 0, '+' ); break;
    
             	default: cout<<"Error";
          	}

  12. #12
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    THANK YOU

    Now on the 5th move it closes....

    Why is that?
    What is C++?

  13. #13
    Registered User
    Join Date
    May 2002
    Posts
    317
    Sorry about the delay, my daughter woke up. Anyhow here you go:

    Code:
    
    for(count = 0; count < 9; count++){
       	makegrid();
                    getch();
                    plyrmve();
                    clrscr();
    }
    Key codes actually return two values,kbit() was seeing two values every time the loop went around therefore for every move you make the loop actually executed twice.

  14. #14
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    YAY!!!

    Thanks Traveller,

    Now i need to figure out what to make with this "engine".

    I would really like to figure out how to use graphics.h to input graphics into my program.

    I tried to make a circle with this header but it said BGI is not supported under windows, what does that mean?
    What is C++?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 10-03-2006, 05:48 PM
  2. THE END - Borland C++ Builder, Delphi, J Builder?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 02-28-2006, 11:23 PM
  3. Visual C++ and Borland C++ Builder :: Breakdown
    By kuphryn in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 02-24-2004, 04:53 PM
  4. Problem with Borland 5.5
    By Gregthatsme in forum C++ Programming
    Replies: 2
    Last Post: 05-25-2003, 09:07 AM
  5. Borland C++ v.5 & Borland Turbo C++ 4.5
    By Unregistered in forum C Programming
    Replies: 0
    Last Post: 07-21-2002, 04:30 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21