954,184 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Moving Objects in Turbo C++

:?: How do you make an object, say a rectangle, move in turbo c++, using right and left arrow keys?

I want the object to move when a user presses right or left arrow keys.

Please reply ASAP either here or at my email <>

joydsouza90
Light Poster
25 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

Use the nonstandard getch() to handle your keyboard input - but beware, it's not supported on all compilers and the input is non-buffered. That being said, there's no C/C++ standard for asynchronous input as far as I know, so using getch() is your best bet.
Using variables to keep track of the object's location, you can then draw it using Turbo's graphics.h file. There's more information about Turbo graphics here: http://www.onecore.net/turbo-c-graphics-programming.htm

Hope this helps

John A
Vampirical Lurker
Team Colleague
7,630 posts since Apr 2006
Reputation Points: 2,240
Solved Threads: 339
 

hey thanx...but i want to know the exact syntax i need to write to make a rectangle move when a user presses the right or left key. I'm new to Turbo c++ and i would really need all the help i can get.

Thanx a lot

joydsouza90
Light Poster
25 posts since Dec 2006
Reputation Points: 10
Solved Threads: 0
 

No one will write the exact code for you.

So do some reading and write it yourself.

iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
 

hey thanx...but i want to know the exact syntax i need to write to make a rectangle move when a user presses the right or left key. I'm new to Turbo c++ and i would really need all the help i can get.

Thanx a lot

Start with something a bit more trivial - Learn how to manipulate user input, and how to generate output first. then you'll be one step towards creating a program which combines input/output.

There is no "exact" syntax for doing what you want.. How you accomplish it is entirely up to you, although you need to learn the basics first, then you'll know what options you have available to you.

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 

everybody can help me?????
i want to know how to do the output moving in coding c++....
HELP ME!!!!!!

kingkong01
Newbie Poster
1 post since Mar 2010
Reputation Points: 10
Solved Threads: 0
 

you can use function getkey() for getting integer for that key

{
int ch;
if(kbhit())
{
      ch=getkey();
 }

switch(ch)
{
//for right errow key     
case 77:
// type your code here i.e. if you press the right errow key this will happen
//gotoxy(x,y)  function can help you here

//for left errow key     
case 75:
// type your code here 

//for up errow key     
case 72:
// type your code here 

//for down errow key     
case 80:
// type your code here 

}


you can make you own program which will let you know the integer value that getkey() returns for all keys..try it yourself

if u get some error like " function getkey should have a prototype " paste goto.c attached with solution file in bin of your turbo cpp compiler.

hope this will hlp ...

Attachments GOTO.C (0.59KB)
kirit275
Newbie Poster
13 posts since Oct 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You