Whats worng with the c++ program I have written ???

princeoo7

On a Journey called Life :P
Adept
Jun 10, 2010
1,131
41
61
Mumbai
Friends this is a simple CG program for creating a bouncing ball :)

I am on windows 7 and using a doxbox emulator for full screen.

I am getting 85 % grey color and rest black color with bouncing ball as out put but as you can see below I haven't used any color element so Why am I getting the grey color ???

Is is just the emulator or any problem in code :annoyed:

Please help !!!

Code:
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
//#include<stdlib.h>
//#include<stdio.h>
#include<math.h>
void main ()
{
 int gd,gm,r,x,y;
 float ym;
 detectgraph(&gd,&gm);
 initgraph(&gd,&gm,"c:\\tc\\bgi");
 x=300;
 y=200;
 r=50;
 ym=400;
 while(!kbhit())
{
 if(y<=ym)
  {
   clrscr();
   y=y+20;
   circle(x,y,r);
   delay(100);
  }
 else
  {
   do
    {
     clrscr();
     y=y-20;
     circle(x,y,r);
     delay(100);
    }
   while(y!=0);
  }
}
getch();
}
 

vishalrao

Global Moral Police
Veteran
Nov 10, 2007
4,593
689
202
Pune, India
Wow, you really are using ancient DOS/TurboC++ stuff it seems :) If my memory serves, clrscr(); only clears block characters off the screen and not the graphics circle(); so you need to either draw over existing circle changing the colour, or locate the function to clear graphics screen as well.
 

princeoo7

On a Journey called Life :P
Adept
Jun 10, 2010
1,131
41
61
Mumbai
Yep Got what you where trying to say :)

Thanks @vishalrao Got the solution :)

It was just clrscr(); which I when replaced with cleardevice(); gave me my desire output :D
 

vishalrao

Global Moral Police
Veteran
Nov 10, 2007
4,593
689
202
Pune, India
Why not get a modern compiler, like the latest Visual Studio 2012 Express edition (free). And if you want to do graphics programming, you could try OpenGL.
 

princeoo7

On a Journey called Life :P
Adept
Jun 10, 2010
1,131
41
61
Mumbai
I am doing this for Computer Graphics @ college :p

Still in S.Y. and they are with TurboC only !!!

T.Y is where I would get a change to bang 2008 I think but best will be latest What I prefer :D

But our teacher are like " Don't try to act smart ! Just use what we tell " :unsure: