943,763 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 8384
  • C++ RSS
Jul 9th, 2005
0

need help correcting "blackjack" c++ game

Expand Post »
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"


C++ Syntax (Toggle Plain Text)
  1. # include <iostream.h>
  2. # include <conio.h>
  3. # include <stdlib.h>
  4.  
  5. void main ()
  6.  
  7. {
  8. clrscr();
  9. int mode=99;
  10. int mode2=69;
  11. int long bal=1000;
  12. int long bet=0;
  13. int con1=1;
  14. int con2=1;
  15. int con3=1;
  16. int con4=1;
  17. int x=0;
  18. int y=0;
  19. int m=0;
  20. int n=0;
  21. int t1=0;
  22. int t2=0;
  23. int c=0;
  24. int d=0;
  25.  
  26. int order;
  27. int order2;
  28. int order3;
  29.  
  30. int order21;
  31. int order22;
  32.  
  33. int t3=0;
  34.  
  35.  
  36. int spil=0;
  37. int spil2=0;
  38.  
  39. randomize();
  40.  
  41. cout<<"INTRO"; //YET TO BE FILLED
  42. getch();
  43. clrscr();
  44.  
  45. while (mode==99)
  46. {
  47.  
  48. clrscr();
  49.  
  50.  
  51.  
  52. cout<<"Enter your bet (YOUR BALANCE= $"<<bal<<" ) : $";
  53. cin>>bet;
  54.  
  55. if (bet==123456789)
  56. {
  57. return;
  58. }
  59.  
  60. if(bet<0)
  61. {
  62. bet=-bet;
  63. }
  64.  
  65. if (bet==420840)
  66. {
  67. cout<<"WOW! the cheat code aye!\n"; //CHEATCODE
  68. bal=1420840;
  69. }
  70.  
  71. if ((bet>bal) && (bal>5))
  72. {
  73. cout<<"You dont have enough cash"<<endl;
  74. cout<<"Your default bet : $"<<bal/100<<endl;
  75. bet=bal/100;
  76. getch();
  77. }
  78.  
  79. if ((bet>bal) && (bet>=1) && (bet<=5))
  80. {
  81. cout<<"You dont have enought cash"<<endl;
  82. cout<<"Your default bet : $1"<<endl;
  83. bet=1;
  84. getch();
  85. }
  86.  
  87. if (bal==0)
  88. {
  89. cout<<"You ran out of money"<<endl;
  90. cout<<"We have decided to throw you out of the casino"<<endl;
  91. getch();
  92. return;
  93. }
  94.  
  95.  
  96. cout<<"Your bet is $"<<bet<<endl;
  97.  
  98. bal=bal-bet;
  99. cout<<"Your new balance : $"<<bal<<endl;
  100. getch();
  101.  
  102. mode2=69; //just took 69 for no reason
  103. while(mode2==69)
  104. {
  105.  
  106.  
  107. clrscr();
  108.  
  109.  
  110. if (con1==1)
  111. {
  112.  
  113. x=random(14)+1;
  114.  
  115. if (x<=10)
  116. {
  117. cout<<"You got card "<<x<<endl;
  118. }
  119.  
  120. if (x==11)
  121. {
  122. cout<<"You got a jack"<<endl;
  123. x=10;
  124. }
  125.  
  126. if (x==12)
  127. {
  128. cout<<"You got a queen"<<endl;
  129. x=10;
  130. }
  131.  
  132. if (x==13)
  133. {
  134. cout<<"You got a King"<<endl;
  135. x=10;
  136. }
  137.  
  138. if (x==14)
  139. {
  140. cout<<"You got a `A'"<<endl;
  141. x=11;
  142. }
  143. }
  144.  
  145.  
  146. if (con2==1)
  147. {
  148.  
  149. y=random(14)+1;
  150. if (y<=10)
  151. {
  152. cout<<"You got card "<<y<<endl;
  153. }
  154.  
  155. if (y==11)
  156. {
  157. cout<<"You got a jack"<<endl;
  158. y=10;
  159. }
  160.  
  161. if (y==12)
  162. {
  163. cout<<"You got a queen"<<endl;
  164. y=10;
  165. }
  166.  
  167. if (y==13)
  168. {
  169. cout<<"You got a King"<<endl;
  170. y=10;
  171. }
  172.  
  173. if (y==14)
  174. {
  175. cout<<"You got a `A'"<<endl;
  176. y=11;
  177. }
  178. }
  179.  
  180. cout<<"\n";
  181.  
  182. if (spil==0)
  183. {
  184. t1=t1+x+y;
  185. cout<<"Your Total : "<<t1;
  186. }
  187.  
  188. if (spil==1)
  189. {
  190. t1=t1+x;
  191. t3=t3+y;
  192. cout<<"Your total 1) "<<t1<<endl;
  193. cout<<"Your total 2) "<<t2<<endl;
  194. }
  195. getch();
  196. cout<<endl<<endl;
  197.  
  198. if ((t1==21) && (t2!=21))
  199. {
  200. cout<<"You got a Black jack"<<endl;
  201. cout<<"You win"<<endl;
  202. bet=bet*2.5;
  203. bal=bal+bet;
  204. c=1;
  205. mode2=0;
  206. d=1;
  207. }
  208.  
  209. if ((t2==21) && (t1!=21))
  210. {
  211. cout<<"Dealer got a Black jack"<<endl;
  212. cout<<"You lose"<<endl;
  213. bet=0;
  214. c=1;
  215. mode2=0;
  216. d=1;
  217. }
  218.  
  219. if ((t2==t1) && (t1==21))
  220. {
  221. cout<<"You and the dealer got a blackjack"<<endl;
  222. cout<<"So you dont win"<<endl;
  223. c=1;
  224. mode2=0;
  225. bet=0;
  226. d=1;
  227. }
  228.  
  229. if ((t1>21) && (t2<=21) && (c==0))
  230. {
  231. cout<<"You burst...!"<<endl;
  232. cout<<"You lose\n";
  233. mode2=0;
  234. d=1;
  235. }
  236.  
  237. if ((t2>21) && (t1<=21) &&(c==0))
  238. {
  239. cout<<"dealer burst...!"<<endl;
  240. cout<<"You w\n";
  241. bet=bet*2;
  242. bal=bal+bet;
  243. mode2=0;
  244. d=1;
  245. }
  246.  
  247.  
  248. if ((con3==1) && (c==0))
  249. {
  250. m=random(14)+1;
  251. if (m<=10)
  252. {
  253. cout<<"Dealer got card "<<m<<endl;
  254. }
  255.  
  256. if (m==11)
  257. {
  258. cout<<"Dealer got a jack"<<endl;
  259. m=10;
  260. }
  261.  
  262. if (m==12)
  263. {
  264. cout<<"Dealer got a queen"<<endl;
  265. m=10;
  266. }
  267.  
  268. if (m==13)
  269. {
  270. cout<<"Dealer got a King"<<endl;
  271. m=10;
  272. }
  273.  
  274. if (m==14)
  275. {
  276. cout<<"Dealer got a `A'"<<endl;
  277. m=11;
  278. }
  279. }
  280.  
  281. if ((con4==1) && (c==0));
  282. {
  283. n=random(14)+1;
  284. if (n<=10)
  285. {
  286. cout<<"Dealer got card "<<n<<endl;
  287. }
  288.  
  289. if (n==11)
  290. {
  291. cout<<"Dealer got a jack"<<endl;
  292. n=10;
  293. }
  294.  
  295. if (n==12)
  296. {
  297. cout<<"Dealer got a queen"<<endl;
  298. n=10;
  299. }
  300.  
  301. if (n==13)
  302. {
  303. cout<<"Dealer got a King"<<endl;
  304. n=10;
  305. }
  306.  
  307. if (n==14)
  308. {
  309. cout<<"Dealer got a `A'"<<endl;
  310. n=11;
  311. }
  312. }
  313.  
  314. if (spil2==1)
  315. {
  316. t2=t2+m;
  317. }
  318. else
  319. {
  320. t2=m+n;
  321. }
  322.  
  323.  
  324. cout<<"\n\n";
  325. cout<<"Dealers total : "<<t2<<endl;
  326. cout<<"\n\n\n";
  327.  
  328.  
  329. if ((t1==21) && (t2!=21))
  330. {
  331. cout<<"You got a Black jack"<<endl;
  332. cout<<"You win"<<endl;
  333. bet=bet*2.5;
  334. bal=bal+bet;
  335. c=1;
  336. mode2=0;
  337. d=1;
  338. }
  339.  
  340. if ((t2==21) && (t1!=21) && (d==0))
  341. {
  342. cout<<"Dealer got a Black jack"<<endl;
  343. cout<<"You lose"<<endl;
  344. bet=0;
  345. c=1;
  346. mode2=0;
  347. d=1;
  348. }
  349.  
  350. if ((t2==t1) && (t1==21))
  351. {
  352. cout<<"You and the dealer got a blackjack"<<endl;
  353. cout<<"So you dont win"<<endl;
  354. c=1;
  355. mode2=0;
  356. bet=0;
  357. d=1;
  358. }
  359.  
  360. if ((t1>21) && (t2<=21) && (c==0))
  361. {
  362. cout<<"You burst...!"<<endl;
  363. cout<<"You lose\n";
  364. mode2=0;
  365. d=1;
  366. }
  367.  
  368. if ((t2>21) && (t1<=21) &&(c==0))
  369. {
  370. cout<<"dealer burst...!"<<endl;
  371. cout<<"You win\n";
  372. bet=bet*2;
  373. bal=bal+bet;
  374. mode2=0;
  375. d=1;
  376. }
  377.  
  378. if ((t2>21) && (t1>21) && (c==0))
  379. {
  380. cout<<"You both burst"<<endl;
  381. cout<<"No-one wins"<<endl;
  382. cout<<"But still you dont get anything..HAHA!"<<endl;
  383. bet=0;
  384. mode2=0;
  385. d=1;
  386. }
  387.  
  388. cout<<"\nPress any key to continue\n\n\n";
  389. getch();
  390.  
  391. if (d==0)
  392. {
  393. con2=0;
  394. con4=0;
  395.  
  396. clrscr();
  397. cout<<"CHOOSE YOUR ORDER"<<endl;
  398. cout<<"1)stay\n";
  399. cout<<"2)hit\n";
  400.  
  401. if (x==y)
  402. {
  403. cout<<"3)split\n";
  404. }
  405. cout<<"ENTER YOUR ORDER : ";
  406. cin>>order;
  407.  
  408. cout<<"\n\n";
  409.  
  410. if (order==1)
  411. {
  412. cout<<"You chose to stay\n";
  413. cout<<"Your final score now is "<<t1<<endl;
  414. con1=0;
  415. }
  416.  
  417. if (order==2)
  418. {
  419. cout<<"You chose to hit\n";
  420. cout<<"Your current score is "<<t1<<endl;
  421. }
  422.  
  423.  
  424. if (spil==1)
  425. {
  426. t1=t1+x;
  427. t3=t3+y;
  428.  
  429. if (order21==1)
  430. {
  431. t1=t1-x;
  432. }
  433.  
  434. if (order22==1)
  435. {
  436. t3=t3-y;
  437. }
  438.  
  439. cout<<"1)You got "<<t1<<endl;
  440. cout<<"2)You got "<<t3<<endl;
  441.  
  442. if (order21==0)
  443. {
  444. cout<<"CHOOSE For the first"<<endl;
  445. cout<<"1)stay\n";
  446. cout<<"2)hit\n";
  447. cout<<"Your choice : ";
  448. cin>>order2;
  449.  
  450. if (order2==1)
  451. {
  452. cout<<"You decided to stay on that card\n";
  453. order21=1;
  454. }
  455.  
  456. if (order2==2)
  457. {
  458. cout<<"You decided to hit\n";
  459. }
  460.  
  461. if (order2>2)
  462. {
  463. cout<<"Thats no choice, dude\n";
  464. cout<<"For not paying attention\n";
  465. cout<<"You have been kicked out of the casino\n";
  466. return;
  467. }
  468.  
  469.  
  470.  
  471. if (order22==0)
  472. {
  473. cout<<"CHOOSE For the second"<<endl;
  474. cout<<"1)stay\n";
  475. cout<<"2)hit\n";
  476. cout<<"Your choice : ";
  477. cin>>order3;
  478.  
  479. if (order3==1)
  480. {
  481. cout<<"You decided to stay on that card\n";
  482. order22=1;
  483. con2=1;
  484. }
  485.  
  486. if (order3==2)
  487. {
  488. cout<<"You decided to hit\n";
  489. }
  490.  
  491. if (order3>2)
  492. {
  493. cout<<"Thats no choice, dude\n";
  494. cout<<"For not paying attention\n";
  495. cout<<"You have been kicked out of the casino\n";
  496. return;
  497. }
  498.  
  499. }
  500. }
  501. }
  502. }
  503.  
  504. if ((order==3) && (x==y) && (spil==0))
  505. {
  506. t1=x;
  507. t3=y;
  508. cout<<"You decided to split\n";
  509. cout<<"Your two different games are of\n";
  510. cout<<"1) "<<t1<<endl;
  511. cout<<"2) "<<t3<<endl;
  512. con2=1;
  513. spil=1;
  514. }
  515.  
  516.  
  517. if ((order>=3) && (x=!y))
  518. {
  519. cout<<"Thats no choice, dude\n";
  520. cout<<"For not paying attention\n";
  521. cout<<"You have been kicked out of the casino\n";
  522. return;
  523. }
  524.  
  525. getch();
  526.  
  527.  
  528. if (d==0)
  529. {
  530. cout<<"\n\n";
  531.  
  532.  
  533. cout<<"Dealer chose to ";
  534.  
  535. if ((t1>t2) && (con1==0) && (con3==0))
  536. {
  537. cout<<"hit";
  538. con4=0;
  539. con3=1;
  540. int n=1;
  541. }
  542.  
  543. if ((t2>17) && ((con1!=0) || (con2!=0)))
  544. {
  545. cout<<"stay";
  546. con4=0;
  547. con3=0;
  548. }
  549.  
  550. if ((t2<18) && (n!=1))
  551. {
  552. cout<<"hit";
  553. con4=0;
  554. con3=0;
  555. }
  556. }
  557. getch();
  558. cout<<endl;
  559. spil2=1;
  560. if ((con1==0) && (con2==0) && (con3==0) && (con4==0))
  561. {
  562.  
  563. if ((t2>=t1) && (t2>=t3) && (spil==1))
  564. {
  565. cout<<"You lost";
  566. }
  567.  
  568. if ((((t2>=t1) && (t2<t3)) || ((t2<t1) && (t2>t3))) && (spil==1))
  569. {
  570. cout<<"You won on one and lost on other";
  571. bet=bet*2;
  572. bal=bal+bet;
  573. }
  574.  
  575. if ((t2<t1) && (t2<t3) && (spil==1))
  576. {
  577. cout<<"You won on both cards";
  578. bet=bet+3;
  579. bal=bal+bet;
  580. }
  581.  
  582. if (t1>t2)
  583. {
  584. cout<<"You won";
  585. bet=bet*2;
  586. bal=bal+bet;
  587. }
  588.  
  589. if (t2>=t1)
  590. {
  591. cout<<"You lost";
  592. }
  593. d=1;
  594. t1=0;
  595. t2=0;
  596. }
  597.  
  598. if (d==1)
  599. {
  600.  
  601. int theend;
  602. cout<<"\nTo exit press 119\n";
  603.  
  604. cout<<"To play again press any other number\n";
  605. cin>>theend;
  606. t1=0;
  607. t2=0;
  608. t3=0;
  609. con1=1;
  610. con2=1;
  611. con3=1;
  612. con4=1;
  613. spil=0;
  614. spil2=0;
  615. d=0;
  616. c=0;
  617. n=1;
  618.  
  619. if (theend==119)
  620. {
  621. mode2=0;
  622. mode=0;
  623. return;
  624.  
  625. }
  626.  
  627. if (theend==999)
  628. {
  629. mode2=0;
  630. }
  631.  
  632. }
  633. x=0;
  634. y=0;
  635. m=0;
  636. n=0;
  637.  
  638. }
  639. //return;
  640. }
  641. }
<< moderator edit: added code tags: [code][/code] >>
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cpp noob is offline Offline
15 posts
since Jul 2005
Jul 9th, 2005
0

Re: need help correcting "blackjack" c++ game

Quote originally posted by cpp noob ...
i would also appeciate a smaller version of this progrm.
Then use subroutines.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Jul 9th, 2005
0

Re: need help correcting "blackjack" c++ game

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
Reputation Points: 51
Solved Threads: 4
Posting Pro in Training
JoBe is offline Offline
420 posts
since Sep 2004
May 1st, 2008
0

Re: need help correcting "blackjack" c++ game

Click to Expand / Collapse  Quote originally posted by JoBe ...
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
Don't bust the kids balls over it. I'm not sure what year of programming you are in, but often times something like this is a final in CS 1.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
CrisRo is offline Offline
1 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: load file data into 2D table
Next Thread in C++ Forum Timeline: Reading the space bar as a charcter in Dev-C++





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC