Home / Animation / Program in C for coin toss

Program in C for coin toss

C program for coin toss

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<graphics.h>
int main(void)
{
int gd=DETECT,gm,errorcode;
int midx,midy,k=1,b=0,a=60;
int xradius,yradius=60;
initgraph(&gd,&gm,"d:\\tc\\bgi");
errorcode =graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
midx = getmaxx() / 2;
midy = getmaxy() / 2;
setcolor(getmaxcolor());
settextstyle(2,0,0);
while(!kbhit())
{
for(a=60;a>=0;a=a-1)
{
cleardevice();
xradius=a;
if(a==0)
{
k=k+1;
for(b=a;b<=60;b++)
{
cleardevice();
xradius=b;
if(k%2==0)
{
outtextxy(midx-10,midy-90,"TAIL");
setfillstyle(4,1);
}
else
{
outtextxy(midx-10,midy-90,"HEAD");
setfillstyle(5,3);
}
if(b>0 && b<57)
{
int xradius1=b-3;
fillellipse(midx,midy,xradius1+1, yradius);
fillellipse(midx,midy,xradius1+2, yradius);
fillellipse(midx,midy,xradius1+3, yradius);
}
outtextxy(10,5,"PROGRAM:TO SHOW THE ROTATION OF A COIN");
fillellipse(midx,midy,xradius, yradius);
delay(25);
}
}
if(a<57>0)
{
int xradius1=a+3;
fillellipse(midx,midy,xradius1-1, yradius);
fillellipse(midx,midy,xradius1-2, yradius);
fillellipse(midx,midy,xradius1-3, yradius);
}
if (k%2==0)
{
outtextxy(midx-10,midy-90,"TAIL");
setfillstyle(4,1);
}
else
{
outtextxy(midx-10,midy-90,"HEAD");
setfillstyle(5,3);
}
outtextxy(10,5,"PROGRAM:TO SHOW THE ROTATION OF A COIN");
fillellipse(midx,midy,xradius, yradius);
delay(25);
}
}
getch();
closegraph();
return 0;}

OUTPUT:

Tags:  c program for coin toss, c program for tossing coin, graphics program for rotating coin.

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.