>>when I tried to run it, it suddenly closed
That's because there is nothing at the end of main() to prevent that behavior. If you want it to stay open so that you can see it, then add getche(); at the end of main(). The program will then stop until you hit a key.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
__avd
Posting Genius (adatapost)
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
>will you please help me about Turbo C?
Turbo C/C++ is a real real old, and an ancient compiler!
Yes we know, but I think his school requires it. :@
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>when I tried to run it, it suddenly closed
That's because there is nothing at the end of main() to prevent that behavior. If you want it to stay open so that you can see it, then add getche(); at the end of main(). The program will then stop until you hit a key.
Dragonmeister!?!?! getche() ?!?!? getchar() please. It's at least standard...
WaltP
Posting Sage w/ dash of thyme
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
Dragonmeister!?!?! getche() ?!?!? getchar() please. It's at least standard...
There is very little about Turbo C that is standard, so it doesn't make any difference whether he uses getche() or not. Could also do this without a problem
while( !kbhit() )
delay(100);
That's not standard either, but works in that old crappy compiler.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I'm guessing that initgraph() fails there and the program just silently exits (i.e. calls exit(1)).
[EDIT]
After looking up initgraph() it's clear that the teacher gave you a bad example (perhaps intentionally?). Anyway, you have to change the call to initgraph() so that it matches the function's signature.
mitrmkar
Posting Virtuoso
1,809 posts since Nov 2007
Reputation Points: 1,105
Solved Threads: 395
A great deal of what you want is included in Turbo C's help files.
After starting up the IDE (the editor inside Turbo C), click on "Help" on the far right hand side, and then on "Index".
One graphic function that you will certainly want to look at is "rectangle" (just start typing it and the help window will take you to it), and maybe "line", and possibly "setcolor", etc.
Along with a full explanation of these functions, it also has a complete sample program you can study and copy and paste, as well.
The above description is for Turbo C/C++ 1.01. Later versions may vary.
Regarding your previous problem - never have your program quit due to an error, without first printing out what the error was. Really elementary stuff like that, will save you a TON of time, in debugging.
Adak
Nearly a Posting Virtuoso
1,479 posts since Jun 2008
Reputation Points: 425
Solved Threads: 185