Well... this is the blackjack game i have to turn it tomorrow....
but it still not finish yet!!!
can someone plz tell me how to do the suit!!!
and the J Q and K...
and also the dealer output will randomly pop out some weired stuffs....
//a dice and card game
//by Samuel Nye
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
#include<stdio.h>
#include <algorithm>
void cards();
void dice();
main()
{
int choice = 1;
cout<<"Welcome to Dice and Carda!\n";
while (choice !=0)
{
cout<<"Press 1 to roll a die or 2 to draw a card, or 0 to quit:";
cin>>choice;
switch (choice)
{
case 0:
cout<<"Thank you for playing!\n";
break;
case 1:
dice();
break;
case 2:
cards();
break;
default:
cout<<"You picked a invaild . Try again.\n";
break;
}
}
return 0;
}
void cards()
{
int cardvalue, value;
int res, res1, res2;
int com1, com2, com3, com4, com5;
int toc, toc1, toc2, toc3;
int user1, user2, user3, user4, user5;
int tou, tou1, tou2, tou3;
int sym;
int color;
if(com1||com2||com3||com4||com5||user1||user2||user3||user4||user5>=10)
{
com1=10;
com2=10;
com3=10;
com4=10;
com5=10;
user1=10;
user2=10;
user3=10;
user4=10;
user5=10;
srand((unsigned)time(NULL)); //setting the randam # generator off time
cout<<char(6)<<char(3)<<char(4)<<char(5)<<endl;
color=0;
//the first one
color = rand()%4+1;
switch(color)
{
case 1:
cout<<char(6);
break;
case 2:
cout<<char(3);
break;
case 3:
cout<<char(4);
break;
default:
cout<<char(5);
break;
}
com1 = rand()%13+1;// assigns a random card 1-13
com2 = rand()%13+1;
toc = com1+com2;//com's total
cout<<"Dealer:"<<color<<com1<<"and"<<"X"<<'\n';
user1 = rand()%13+1;// assigns a random card 1-13
user2 = rand()%13+1;
tou = user1+user2;//user's total
cout<<"You:"<<color<<user1<<"and"<<color<<user2<<"("<<tou<<")\n";
cout<<"Would you like a card??(1-YES, 2-NO)\n";
cin>>res;
color = rand()%4+1;
cout<<color<<'\n';
//the user want one more card(1, total=3 cards)
if(res==1)
{
cout<<"Dealer:"<<com1<<"and"<<"X"<<'\n';
user3 = rand()%13+1;
tou1 = user1+user2+user3;//user add card's total
cout<<"You:"<<user1<<"and"<<user2<<"and"<<user3<<"("<<tou1<<")\n";
//the user bust for adding one more card
if(tou1>21)
{
cout<<"You went bust!\n";
cout<<"The dealer turns over his cards and has"<<com1<<"and"<<com2<<"("<<toc<<")\n";
cout<<"Dealer win!!\n";
}
}
//the user didnt bust and ask if user want one more card
if(tou1<=21)
{
cout<<"Would you like a card??(1-YES, 2-NO)\n";
cin>>res1;
}
//the user want one more card(2 total=4 cards)
if(res1==1)
{
cout<<"Dealer:"<<com1<<"and"<<"X"<<'\n';
user4 = rand()%13+1;
tou2 = user1+user2+user3+user4;//user add two card's total
cout<<"You have the card"<<user1<<"and"<<user2<<"and"<<user3<<"and"<<user4<<"("<<tou2<<")\n";
//the user bust for adding two more cards
if(tou2>21)
{
cout<<"You went bust!\n";
cout<<"The dealer turns over his cards and has"<<com1<<"and"<<com2<<"("<<toc<<")\n";
cout<<"Dealer win!!\n";
}
}
//the user didnt bust again and ask if user want one more card
if(tou2<=21)
{
cout<<"Would you like a card??(1-YES, 2-NO)\n";
cin>>res2;
}
//the user want one more card(3 total=5 cards)
if(res2==1)
{
cout<<"Dealer:"<<com1<<"and"<<"X"<<'\n';
user5 = rand()%13+1;
tou3 = user1+user2+user3+user4+user5;//user add three card's total
cout<<"You have the card"<<user1<<"and"<<user2<<"and"<<user3<<"and"<<user4<<"and"<<user5<<"("<<tou3<<")\n";
//the user bust for adding three more cards
if (tou3>21)
{
cout<<"You went bust!\n";
cout<<"The dealer turns over his cards and has:"<<com1<<"and"<<com2<<"("<<toc<<")\n";
cout<<"Dealer win!!\n";
}
}