answersLogoWhite

0


Best Answer

#include //made by debjyoti dasghosh

#include
#include //if u have any problem email me at //debjyoti.dasghosh@Yahoo.com
#include
#include
int us,cs,flag=0;
void bat();
void bowl();
void cbat();
void cbowl();
void main()

{

start :

textcolor(3);

us=cs=flag=0;

clrscr();

char toss,name[30];

int rand;

randomize();

cout<<"\n\n\t\tHand Cricket.....\n\n\n\tTOSS\n\t\n\nHead Or Tail \n\nEnter H / T : ";

toss=toupper(getch());

if((toss!='H')&&(toss!='T'))

{

cout<<"\a\n\nEnter H Or T : ";

delay(1000);

goto start;

}

cout<

int i=1;

while(!kbhit())

{

rand=random(2);

switch(rand)

{

case 0 : cout<<" Head ";break;

case 1 : cout<<" Tail ";break;

}

if((i%11)==0)

cout<<'\n';

delay(50);

i++;

}

getch();

redo :

switch(rand)

{

case 0 : if(toss=='H')

{

cout<<"\nYou Won The Toss !!\n\n\nBatting Or Bowling ? \n\nEnter B / L : ";

toss=toupper(getch());

cout<

if(toss=='B')

bat();

else if(toss=='L')

bowl();

else

{

cout<<"\n\nPlease Enter Correct Option : ";

sound(700);

delay(750);

nosound();

toss='H';

goto redo;

}

}

else if(toss=='T')

{

cout<<"\n\nComputer Wins The Toss !! \n\n";

switch(rand)

{

case 0 : cout<<"\n\nComputer Choose To Bat ! ";

getch();

bowl();

break;

case 1 : cout<<"\n\nComputer Choose To Bowl ! ";

getch();

bat();

break;

}

}break;

case 1 : if(toss=='T')

{

cout<<"\nYou Won The Toss !!\n\n\nBatting Or Bowling ? \n\nEnter B / L : ";

toss=toupper(getch());

cout<

if(toss=='B')

bat();

else if(toss=='L')

bowl();

else

{

cout<<"\n\nPlease Enter Correct Option : ";

sound(700);

delay(750);

nosound();

toss='H';

goto redo;

}

}

else if(toss=='H')

{

cout<<"\n\nComputer Wins The Toss !! \n\n";

switch(rand)

{

case 0 : cout<<"\n\nComputer Choose To Bat ! ";

getch();

bowl();

break;

case 1 : cout<<"\n\nComputer Choose To Bowl ! ";

getch();

bat();

break;

}

}break;

}

if(us>cs)

{

cout<<"\n\n\t\t\t***You Win !! ***";

}

else if(cs>us)

{

cout<<"\n\n\t\t\t***Computer Win !! ***";

}

else

{

cout<<"\n\n\t\t\t***Match TIED";

}

cout<<"\n\nDo You Want To Play Again ? \n\nEnter Y / N : ";

toss=toupper(getch());

cout<

if(toss=='N')

{

cout<<"\n\nThankYou For Playing This Game !!";

delay(2000);

}

else

goto start;

getch();

}

void bat()

{

textcolor(5);

clrscr();

randomize();

cout<<"\n\n\n\nUser Batting !\n\n";

int u,c;

do

{

if(flag!=0)

{

if((cs-us)<0)

{

cout<<"\n\n\nYou Win !!";

goto end;

}

cout<<"\n\nYou Need "<<(cs-us)<<" Runs To Win ! ";

}

cout<<"\n\nEnter Shot 1 to 4 and 6 : ";

u=getche();

u-=48;

if((u>6)(u==0)(u==5))

{

cout<<"\aInvalid Shot ! ";

continue;

}

c=random(5);

switch(c)

{

case 0 : c=1 ;break;

case 1 : c=2 ;break;

case 2 : c=3 ;break;

case 3 : c=4 ;break;

case 4 : c=6 ;break;

}

if(u!=c)

{

us+=u;

cout<<"\nYou Win "<

}

else

{

cout<<"\n\nYou Are OUT \n\nYou Have "<

}

}while(u!=c);

getch();

if(flag==0)

{

flag=1;

bowl();

}

end :

}

void bowl()

{

textcolor(2);

clrscr();

randomize();

int u,c;

cout<<"\n\n\n\nUser Bowling !\n\n";

do

{

if(flag!=0)

{

if((us-cs)<0)

{

cout<<"\n\n\nComputer Wins !! ";

goto end;

}

cout<<"\n\nComputer Needs "<<(us-cs)<<" Runs To Win ! \n\n";

}

cout<<"\n\nEnter Style 1 to 4 and 6 : ";

u=getche();

u-=48;

if((u>6)(u==0)(u==5))

{

cout<<"\aInvalid Style ! ";

continue;

}

c=random(5);

switch(c)

{

case 0 : c=1 ;break;

case 1 : c=2 ;break;

case 2 : c=3 ;break;

case 3 : c=4 ;break;

case 4 : c=6 ;break;

}

if(u!=c)

{

//cout<

cs+=c;

cout<<"\nComputer Win "<

}

else

{

cout<<"\n\nYou Have Bowled Out The Computer \n\nComputer Have "<

}

}while(u!=c);

getch();

if(flag==0)

{

flag=1;

bat();

}

end:

}

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you program a cricket game in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering
Related questions

What is a C plus plus game project program?

A C++ game project program could either be a game written in C++ or a C++ library that helps you develop a game.


Is c plus plus can be used in game programming?

yes! why not! this c program is used in ATM servicesand also in games.


Can you program games with c plus plus?

Yes, you can program games with C++.


How to restart c plus plus program?

Exit the program and relaunch it.


Lint is a compiler b a interactive debugger c a cinterpreter d a tool for analysing c plus plus program?

d a tool for analysing c plus plus program


How do you write a C plus plus program that will display the first 10 positive prime numbers?

By learning how to program on C+.


Where did C plus plus program come from?

C++ is an extension of C, and was invented by Bjarne Stroustrup.


What is the only function all C plus plus programs must contain?

Every C plus plus program that is a main program must have the function 'main'.


Can you rewrite a cuda file in c c plus plus language?

Yes, you can rewrite a cuda program originally written in c in c plus plus.


What are the Example Output of Calculator Program in C plus plus?

example output of c++ calculator


When was the game of cricket invented?

Game of cricket has been started in the year of 16th century and from 1844 various international cricket matches were played and in 1877 official history of international test cricket begin.


How does algorithm and c plus plus program get along?

They are bosom-friends.