The below program is working but it have some constraint

#include<windows.h>
#include<iostream>
using namespace std;
void gotoxy(int x,int y)
{
COORD CursorPosition;
CursorPosition.X=x;
CursorPosition.Y=y;
SetConsoleCursorPosition((GetStdHandle(STD_OUTPUT_HANDLE)),CursorPosition);
}
void decone(int num,char suit,int x,int y)
{
int i;
for(i=0;i<200000000;i++);
gotoxy(x,y);
for(i=0;i<11;i++)
{
cout<<"*";
}
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*  "<<suit;
gotoxy(x+7,y);
cout<<suit<<"  *";
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*";
if(num==11)
{
gotoxy(x+5,y);
cout<<"J";
}
else if(num==12)
{
gotoxy(x+5,y);
cout<<"Q";
}
else if(num==0)
{
gotoxy(x+5,y);
cout<<"K";
}
else if(num==1)
{
gotoxy(x+5,y);
cout<<"A";
}
else if(num>1 && num<11)
{
gotoxy(x+5,y);
cout<<num;
}
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*  "<<suit;
gotoxy(x+7,y);
cout<<suit<<"  *";
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
for(i=0;i<11;i++)
{
cout<<"*";
}
cout<<endl;
}
int calculate(int num1,int num2)
{
int sum=0,sum1=0,user[2];
user[0]=num1;
user[1]=num2;
if(user[0]!=1&&user[1]!=1)
{
if(user[0]>1&&user[0]<11)
{
sum=sum+user[0];
sum1=sum1+user[0];
}
else if(user[0]==0||user[0]==11||user[0]==12)
{
sum=sum+10;
sum1=sum1+10;
}
if(user[1]>1&&user[1]<11)
{
sum=sum+user[1];
sum1=sum1+user[1];
}
else if(user[1]==0||user[1]==11||user[1]==12)
{
sum=sum+10;
sum1=sum1+10;
}                          
}
else if(user[0]==1&&user[1]==1)
{
sum=2;
sum1=12;
}
else if(user[0]==1&&user[1]!=1)
{
if(user[1]==0||user[1]==10||user[1]==11||user[1]==12)
{
sum=21;
sum1=21;
}
else
{
sum=11+user[1];
sum1=1+user[1];
}
}
else if(user[1]==1&&user[0]!=1)
{
if(user[0]==0||user[0]==10||user[0]==11||user[0]==12)
{
sum=21;
sum1=21;
}
else
{
sum=11+user[0];
sum1=1+user[0];
}
}
if(sum==sum1)
{
cout<<"The sum is "<<sum<<endl;
}
else
{
cout<<"The sum is "<<sum1<<" or "<<sum<<endl; 
}
return(sum);
}
int calculatehit(int sum,int hit,int posy)
{
int sum1=sum;
if(hit>1&&hit<11)
{
sum=sum+hit;
sum1=sum1+hit;
}
else if(hit==0||hit==11||hit==12)
{
sum=sum+10;
sum1=sum1+10;
}
else if(hit==1)
{
sum=sum+1;
if(sum1<=10)
sum1=sum1+11;
else
sum1=sum;
}
gotoxy(0,posy+9);
cout<<"\t\t\t\t";
if(sum==sum1)
{
gotoxy(0,posy+9);
cout<<"The sum is "<<sum<<endl;
}
else
{
gotoxy(0,posy+9);
cout<<"The sum is "<<sum<<" or "<<sum1<<endl; 
}
return(sum);
}
int hit(int sum,int posx,int posy)
{
int temp;
char suit;
temp=rand()%13;
suit=rand()%4+3;
decone(temp,suit,posx,posy); 
sum=calculatehit(sum,temp,posy);
return sum;  
}
main()
{
int x=1;
while(x==1)
{
int comp,user[2],i,choice,sum,comsum,userposx=0,userposy=16,composx=0,composy=2;
char comsuit,usersuit1,usersuit2;
srand(time(0));
comsum=rand()%13;
comsuit=rand()%4+3;
usersuit1=rand()%4+3;
usersuit2=rand()%4+3;
for(i=0;i<2;i++)
{
user[i]=rand()%13;
}
cout<<"Computer card is\n";
decone(comsum,comsuit,composx,composy);
composx=composx+12;
gotoxy(0,14);
cout<<"Your cards are\n";
decone(user[0],usersuit1,userposx,userposy);
userposx=userposx+12;
decone(user[1],usersuit2,userposx,userposy);
userposx=userposx+12;
sum=calculate(user[0],user[1]);
l:
if(sum!=21)
{
gotoxy(0,28);
cout<<"Enter your choice\n1. Hit\n2. Stand\n"; 
cin>>choice;
switch(choice)
{
case 1:
{
sum=hit(sum,userposx,userposy);
if(sum<21)
{
userposx=userposx+12;;
goto l;
}
else if(sum>21)
{
gotoxy(30,32);
cout<<"Burst\n";
gotoxy(27,33);
cout<<"Dealer wins\n";
goto m;
}
else if(sum==21)
{}
}
case 2:
{
int comptemp=rand()%13;
int compsuit2=rand()%4+3;
decone(comptemp,compsuit2,composx,composy);
comsum=calculate(comsum,comptemp);
composx=composx+12;
while(comsum<17)
{
comsum=hit(comsum,composx,composy);
composx=composx+12;
}
if(comsum>sum&&comsum<22)
{
gotoxy(30,32);
cout<<"Dealer wins\n";
}
else if(comsum==sum)
{
gotoxy(30,32);
cout<<"Draw\n";
}
else
{
gotoxy(30,32);
cout<<"You win\n";
}
}
}
}
else
{
gotoxy(30,32);
cout<<"Congratulation Blackjack\n";
}
m:
gotoxy(0,35);
cout<<"press 1 to continue\n";
cin>>x;
system("cls");
}
system("pause");
}

You'll have to explain the "constraints" -- I don't want to guess or read your mind.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.