Reputation: 1
I am relatively new to programming and for my school project, I want to make use of buttons in my program, so I made an experimental program in Turbo C++ to see whether my logic works or not.
The idea of my experimental program is that when the mouse cursor is inside the square displayed in the output screen and the user clicks, the program should exit. The problem is that the program works as expected only once. If it is run again, the program exits even if the mouse button is not clicked (that is, the program exits the moment the cursor is inside the square, regardless of the status of the click). This is my experimental program :
#include<process.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
union REGS in,out;
void main()
{
int gdriver = DETECT,gmode;
int xp,yp,cl=0;
int x,y;
initgraph(&gdriver,&gmode,"C:\\Turboc3\\BGI");
x=getmaxx()/2;
y=getmaxy()/2;
in.x.ax=4;
in.x.cx=10;
in.x.dx=10;
int86(51,&in,&out);
in.x.ax=1;
int86(51,&in,&out);
setcolor(RED);
rectangle((x-100),(y-100),x,y);
in.x.ax=3;
do
{
int86(51,&in,&out);
cl=out.x.bx; //Status of click
xp=out.x.cx; //X-co-ordinate
yp=out.x.dx; //Y-co-ordinate
}while(!((cl==1)&&(((xp>x-100)&&(xp<x))&&((yp>y-100)&&(yp<y))));
}
If there is a problem in my logic, please tell me what it is. Any and all help is highly appreciated. And please do not make condescending remarks about my choice of Compiler. I am forced to work in Turbo C++ because my school does not allow me to work in any other IDE.
Upvotes: 0
Views: 3206
Reputation: 23
Put the TurbidCrap++ in the bin, it's over 20 years old and half a dozen versions of windows have passed it by since then. Think about it, people who used this in the past stopped using it long ago. Few people remain who could actually answer your questions, and fewer still can be bothered with TC any more.
Get a compiler which is compatible with your actual real OS, and not some hacky emulation of fossilised DOS.
Examples- codeblocks
Upvotes: 1