So i made a c++ program to draw a line with DDA algorithm, i want to fins how long fast the program finish, but it's seems that the clock function i put can not be printed out
#include <iostream>
#include <graphics.h>
#include <conio.h>
#include <time.h>
using namespace std;
int opt, x1 = 50, y1 =50, x2 = 50, y2=200;
int xt, yt;
int dx;
int dy;
int i;
int j;
int up;
int gd = DETECT, gm;
int main()
{
clock_t exe, exe2;
exe = clock();
dx=(x2-x1);
dy=(y2-y1);
if(dx > dy)
up=dx;
else
up=dy;
float xi=(x2-x1)/up;
float yi=(y2-y1)/up;
int x=x1;
int y=y1;
int xt=x1;
int yt=y1;
initgraph(&gd, &gm, "C:\\TC\\BGI");
putpixel(x,y, 15);
for(j=1;j<=500;j++)
{
for(i=1;i<=up;i++)
{
x += xi;
y += yi;
putpixel(abs(x),abs(y), 15);
}
x = xt;
y=yt;
}
getch();
closegraph();
exe2 = clock();
float diff = ((float)exe2 - (float)exe);
cout << "The time: " << diff << endl;
system("pause");
return 0;
}
the line is showed up in the graphic window, but after i close the graphic window, the program just stop without showing the result from diff