Hi friends
I am a beginer in C. I want to make a simple program in which there
are two balls on the screen.
These two balls will Strike when the user presses any key ?
Please help me with full code snippets.

Which Compiler are you using..?If Turbo C++..,You have to know little about the functions under graphics.h.

Actually this question has more to do with what OS(unless its, doubtfully, hardware specific).

Just use something like OpenGL or SDL, for graphics.

Dude,,, It's a little harder to understand the graphics functions..

For this you must have the knowledge of the functions defined in graphics.h,,,,,:|

What is with all the Turbo C++ references?!! That compiler is a non-standard relic from another millennial! It's useless!

Comments
Gotta keep banging the drum!
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
int i=100,j=100,f1=1,f2=1,r=50,k;
l:
// printf("\n\nEnter the co-ordinate where from you want to start to move the circle : ");
// scanf("%d%d",&i,&j);
cleardevice();
// printf("\n\nEnter the redious : " );
// scanf("%d",&r);
// if(r<i||r<j) {printf("\nWrong entry, Try again.");goto l;}
cleardevice();
getch();
while(!kbhit())
{

setcolor(WHITE);
circle(i+1,j+1,r); // printf("%d, %d",i,j);
delay(2);
/* for(k=1;k<=10;k++)
{
setcolor(k);
circle(i+1,j+1,r-(k*r/10));
delay(1);
setcolor(BLACK);
circle(i+1,j+1,r-(k*r/10));
} */
setcolor(BLACK);

circle(i+1,j+1,r);
if(i<639-r&&f1==1)
{i++;f1=1;
}
else
{i--;
if(i==r) f1=1; else f1=-1;
}
if(j<480-r&&f2==1)
{j++;f2=1;}
else
{j--;
if(j==r) f2=1;else f2=-1;
}

}
}








Try this , Here is one single ball, read it try to upgrade into two balls
Comments
More unindented TurboC crap on the end of a thread that died long ago
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
void main()
{
int gdriver=DETECT,gmode;
initgraph(&gdriver,&gmode,"c:\\tc\\bgi");
int i=100,j=100,f1=1,f2=1,r=50,k;
l:
// printf("\n\nEnter the co-ordinate where from you want to start to move the circle : ");
// scanf("%d%d",&i,&j);
cleardevice();
// printf("\n\nEnter the redious : " );
// scanf("%d",&r);
// if(r<i||r<j) {printf("\nWrong entry, Try again.");goto l;}
cleardevice();
getch();
while(!kbhit())
{

setcolor(WHITE);
circle(i+1,j+1,r); // printf("%d, %d",i,j);
delay(2);
/* for(k=1;k<=10;k++)
{
setcolor(k);
circle(i+1,j+1,r-(k*r/10));
delay(1);
setcolor(BLACK);
circle(i+1,j+1,r-(k*r/10));
} */
setcolor(BLACK);

circle(i+1,j+1,r);
if(i<639-r&&f1==1)
{i++;f1=1;
}
else
{i--;
if(i==r) f1=1; else f1=-1;
}
if(j<480-r&&f2==1)
{j++;f2=1;}
else
{j--;
if(j==r) f2=1;else f2=-1;
}

}
}








Try this , Here is one single ball, read it try to upgrade into two balls

Don't use "void main()", there are two proper main function headers, and they are:

int main(int argc, char *argv[]) and int main()

Using "void main()" can cause problems, for a detailed explanation as to what kind of problems it can cause please consult google.


and for your information if you ever want to upgrade to a newer compiler, (like Visual Studio Express, or MinGW) the first thing you should try is using STANDARD C++ headers, like instead of "fstream.h" it should be #include <fstream>

This article has been dead for over six months. Start a new discussion instead.