| | |
need help correcting "blackjack" c++ game
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2005
Posts: 15
Reputation:
Solved Threads: 0
hello
i made this black jack game its showing few bugs and stuff , spent a long
time and i cannot figure out what to do . please help correcting :cry:
i would also appeciate a smaller version of this progrm. :surprised
thank you :cry:
this is for "tc.exe"
<< moderator edit: added code tags: [code][/code] >>
i made this black jack game its showing few bugs and stuff , spent a long
time and i cannot figure out what to do . please help correcting :cry: i would also appeciate a smaller version of this progrm. :surprised
thank you :cry:
this is for "tc.exe"
C++ Syntax (Toggle Plain Text)
# include <iostream.h> # include <conio.h> # include <stdlib.h> void main () { clrscr(); int mode=99; int mode2=69; int long bal=1000; int long bet=0; int con1=1; int con2=1; int con3=1; int con4=1; int x=0; int y=0; int m=0; int n=0; int t1=0; int t2=0; int c=0; int d=0; int order; int order2; int order3; int order21; int order22; int t3=0; int spil=0; int spil2=0; randomize(); cout<<"INTRO"; //YET TO BE FILLED getch(); clrscr(); while (mode==99) { clrscr(); cout<<"Enter your bet (YOUR BALANCE= $"<<bal<<" ) : $"; cin>>bet; if (bet==123456789) { return; } if(bet<0) { bet=-bet; } if (bet==420840) { cout<<"WOW! the cheat code aye!\n"; //CHEATCODE bal=1420840; } if ((bet>bal) && (bal>5)) { cout<<"You dont have enough cash"<<endl; cout<<"Your default bet : $"<<bal/100<<endl; bet=bal/100; getch(); } if ((bet>bal) && (bet>=1) && (bet<=5)) { cout<<"You dont have enought cash"<<endl; cout<<"Your default bet : $1"<<endl; bet=1; getch(); } if (bal==0) { cout<<"You ran out of money"<<endl; cout<<"We have decided to throw you out of the casino"<<endl; getch(); return; } cout<<"Your bet is $"<<bet<<endl; bal=bal-bet; cout<<"Your new balance : $"<<bal<<endl; getch(); mode2=69; //just took 69 for no reason while(mode2==69) { clrscr(); if (con1==1) { x=random(14)+1; if (x<=10) { cout<<"You got card "<<x<<endl; } if (x==11) { cout<<"You got a jack"<<endl; x=10; } if (x==12) { cout<<"You got a queen"<<endl; x=10; } if (x==13) { cout<<"You got a King"<<endl; x=10; } if (x==14) { cout<<"You got a `A'"<<endl; x=11; } } if (con2==1) { y=random(14)+1; if (y<=10) { cout<<"You got card "<<y<<endl; } if (y==11) { cout<<"You got a jack"<<endl; y=10; } if (y==12) { cout<<"You got a queen"<<endl; y=10; } if (y==13) { cout<<"You got a King"<<endl; y=10; } if (y==14) { cout<<"You got a `A'"<<endl; y=11; } } cout<<"\n"; if (spil==0) { t1=t1+x+y; cout<<"Your Total : "<<t1; } if (spil==1) { t1=t1+x; t3=t3+y; cout<<"Your total 1) "<<t1<<endl; cout<<"Your total 2) "<<t2<<endl; } getch(); cout<<endl<<endl; if ((t1==21) && (t2!=21)) { cout<<"You got a Black jack"<<endl; cout<<"You win"<<endl; bet=bet*2.5; bal=bal+bet; c=1; mode2=0; d=1; } if ((t2==21) && (t1!=21)) { cout<<"Dealer got a Black jack"<<endl; cout<<"You lose"<<endl; bet=0; c=1; mode2=0; d=1; } if ((t2==t1) && (t1==21)) { cout<<"You and the dealer got a blackjack"<<endl; cout<<"So you dont win"<<endl; c=1; mode2=0; bet=0; d=1; } if ((t1>21) && (t2<=21) && (c==0)) { cout<<"You burst...!"<<endl; cout<<"You lose\n"; mode2=0; d=1; } if ((t2>21) && (t1<=21) &&(c==0)) { cout<<"dealer burst...!"<<endl; cout<<"You w\n"; bet=bet*2; bal=bal+bet; mode2=0; d=1; } if ((con3==1) && (c==0)) { m=random(14)+1; if (m<=10) { cout<<"Dealer got card "<<m<<endl; } if (m==11) { cout<<"Dealer got a jack"<<endl; m=10; } if (m==12) { cout<<"Dealer got a queen"<<endl; m=10; } if (m==13) { cout<<"Dealer got a King"<<endl; m=10; } if (m==14) { cout<<"Dealer got a `A'"<<endl; m=11; } } if ((con4==1) && (c==0)); { n=random(14)+1; if (n<=10) { cout<<"Dealer got card "<<n<<endl; } if (n==11) { cout<<"Dealer got a jack"<<endl; n=10; } if (n==12) { cout<<"Dealer got a queen"<<endl; n=10; } if (n==13) { cout<<"Dealer got a King"<<endl; n=10; } if (n==14) { cout<<"Dealer got a `A'"<<endl; n=11; } } if (spil2==1) { t2=t2+m; } else { t2=m+n; } cout<<"\n\n"; cout<<"Dealers total : "<<t2<<endl; cout<<"\n\n\n"; if ((t1==21) && (t2!=21)) { cout<<"You got a Black jack"<<endl; cout<<"You win"<<endl; bet=bet*2.5; bal=bal+bet; c=1; mode2=0; d=1; } if ((t2==21) && (t1!=21) && (d==0)) { cout<<"Dealer got a Black jack"<<endl; cout<<"You lose"<<endl; bet=0; c=1; mode2=0; d=1; } if ((t2==t1) && (t1==21)) { cout<<"You and the dealer got a blackjack"<<endl; cout<<"So you dont win"<<endl; c=1; mode2=0; bet=0; d=1; } if ((t1>21) && (t2<=21) && (c==0)) { cout<<"You burst...!"<<endl; cout<<"You lose\n"; mode2=0; d=1; } if ((t2>21) && (t1<=21) &&(c==0)) { cout<<"dealer burst...!"<<endl; cout<<"You win\n"; bet=bet*2; bal=bal+bet; mode2=0; d=1; } if ((t2>21) && (t1>21) && (c==0)) { cout<<"You both burst"<<endl; cout<<"No-one wins"<<endl; cout<<"But still you dont get anything..HAHA!"<<endl; bet=0; mode2=0; d=1; } cout<<"\nPress any key to continue\n\n\n"; getch(); if (d==0) { con2=0; con4=0; clrscr(); cout<<"CHOOSE YOUR ORDER"<<endl; cout<<"1)stay\n"; cout<<"2)hit\n"; if (x==y) { cout<<"3)split\n"; } cout<<"ENTER YOUR ORDER : "; cin>>order; cout<<"\n\n"; if (order==1) { cout<<"You chose to stay\n"; cout<<"Your final score now is "<<t1<<endl; con1=0; } if (order==2) { cout<<"You chose to hit\n"; cout<<"Your current score is "<<t1<<endl; } if (spil==1) { t1=t1+x; t3=t3+y; if (order21==1) { t1=t1-x; } if (order22==1) { t3=t3-y; } cout<<"1)You got "<<t1<<endl; cout<<"2)You got "<<t3<<endl; if (order21==0) { cout<<"CHOOSE For the first"<<endl; cout<<"1)stay\n"; cout<<"2)hit\n"; cout<<"Your choice : "; cin>>order2; if (order2==1) { cout<<"You decided to stay on that card\n"; order21=1; } if (order2==2) { cout<<"You decided to hit\n"; } if (order2>2) { cout<<"Thats no choice, dude\n"; cout<<"For not paying attention\n"; cout<<"You have been kicked out of the casino\n"; return; } if (order22==0) { cout<<"CHOOSE For the second"<<endl; cout<<"1)stay\n"; cout<<"2)hit\n"; cout<<"Your choice : "; cin>>order3; if (order3==1) { cout<<"You decided to stay on that card\n"; order22=1; con2=1; } if (order3==2) { cout<<"You decided to hit\n"; } if (order3>2) { cout<<"Thats no choice, dude\n"; cout<<"For not paying attention\n"; cout<<"You have been kicked out of the casino\n"; return; } } } } } if ((order==3) && (x==y) && (spil==0)) { t1=x; t3=y; cout<<"You decided to split\n"; cout<<"Your two different games are of\n"; cout<<"1) "<<t1<<endl; cout<<"2) "<<t3<<endl; con2=1; spil=1; } if ((order>=3) && (x=!y)) { cout<<"Thats no choice, dude\n"; cout<<"For not paying attention\n"; cout<<"You have been kicked out of the casino\n"; return; } getch(); if (d==0) { cout<<"\n\n"; cout<<"Dealer chose to "; if ((t1>t2) && (con1==0) && (con3==0)) { cout<<"hit"; con4=0; con3=1; int n=1; } if ((t2>17) && ((con1!=0) || (con2!=0))) { cout<<"stay"; con4=0; con3=0; } if ((t2<18) && (n!=1)) { cout<<"hit"; con4=0; con3=0; } } getch(); cout<<endl; spil2=1; if ((con1==0) && (con2==0) && (con3==0) && (con4==0)) { if ((t2>=t1) && (t2>=t3) && (spil==1)) { cout<<"You lost"; } if ((((t2>=t1) && (t2<t3)) || ((t2<t1) && (t2>t3))) && (spil==1)) { cout<<"You won on one and lost on other"; bet=bet*2; bal=bal+bet; } if ((t2<t1) && (t2<t3) && (spil==1)) { cout<<"You won on both cards"; bet=bet+3; bal=bal+bet; } if (t1>t2) { cout<<"You won"; bet=bet*2; bal=bal+bet; } if (t2>=t1) { cout<<"You lost"; } d=1; t1=0; t2=0; } if (d==1) { int theend; cout<<"\nTo exit press 119\n"; cout<<"To play again press any other number\n"; cin>>theend; t1=0; t2=0; t3=0; con1=1; con2=1; con3=1; con4=1; spil=0; spil2=0; d=0; c=0; n=1; if (theend==119) { mode2=0; mode=0; return; } if (theend==999) { mode2=0; } } x=0; y=0; m=0; n=0; } //return; } }
Hi cpp noob,
You know, no offence ment, but maybe you'd better learn how to program correctly before you start tackling game programming.
Though I'm no programmer and I'm still learning it myself, I can see, you have little or no experience.
You didn't use switches to simplify the several selections you made
You didn't use any functions in wich several pieces of code could have been written, thus simplifying your code straight away.
Don't take this the wrong way, but, you'd be doing yourself a big favor when you would start and learn the syntax and simple exercises from books, when you master those and have a good understanding of that. Then you could try to write a game
Hope you don't take this the wrong way ok
You know, no offence ment, but maybe you'd better learn how to program correctly before you start tackling game programming.
Though I'm no programmer and I'm still learning it myself, I can see, you have little or no experience.
You didn't use switches to simplify the several selections you made
You didn't use any functions in wich several pieces of code could have been written, thus simplifying your code straight away.Don't take this the wrong way, but, you'd be doing yourself a big favor when you would start and learn the syntax and simple exercises from books, when you master those and have a good understanding of that. Then you could try to write a game
Hope you don't take this the wrong way ok
•
•
Join Date: May 2008
Posts: 1
Reputation:
Solved Threads: 0
•
•
•
•
Hi cpp noob,
You know, no offence ment, but maybe you'd better learn how to program correctly before you start tackling game programming.
Though I'm no programmer and I'm still learning it myself, I can see, you have little or no experience.
You didn't use switches to simplify the several selections you madeYou didn't use any functions in wich several pieces of code could have been written, thus simplifying your code straight away.
Don't take this the wrong way, but, you'd be doing yourself a big favor when you would start and learn the syntax and simple exercises from books, when you master those and have a good understanding of that. Then you could try to write a game![]()
Hope you don't take this the wrong way ok
![]() |
Similar Threads
- "Craps", Game Help (C++)
- Help in "Snake" game using C programming for the AVR (C)
- "Free Roam" Game Suggestions? (Geeks' Lounge)
- Formatting "Buzz - Fizz" Game, help! (Pascal and Delphi)
Other Threads in the C++ Forum
- Previous Thread: load file data into 2D table
- Next Thread: Reading the space bar as a charcter in Dev-C++
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






