Posted By

npanagakis on 06/20/11


Tagged

game snippet Blackjack npanagakis


Versions (?)

blackjack


 / Published in: C++
 

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. using namespace std;
  6. int main ()
  7. {
  8. int loopx;
  9. loopx = 1;
  10. while(loopx == 1){
  11. int computer;
  12. int player;
  13. int addon;
  14. srand ( time(NULL) );
  15. computer = rand() % 23 + 4;
  16. player = rand() % 21 + 4;
  17. addon = rand() % 11 + 1;
  18. int loop = 1;
  19. while (loop == 1){
  20. cout << "New round... your cards: " << player;
  21. string response;
  22. cin >> response;
  23. if(response == "done"){
  24. cout << "ok then...";
  25. loop = 0;
  26. }
  27. if(response == "hitme"){
  28. cout << "ok then...";
  29. player = player + addon;
  30. cout << "your new cards are equal to " << player;
  31. }
  32. if(player>computer){
  33. if(player<22){
  34. cout << "you won! Computer's cards:" << computer;
  35. loop = 0;
  36. }
  37. if (player>21){
  38. cout << "you lose! Computer's cards:" << computer;
  39. loop = 0;
  40. }
  41. }
  42. if(computer>player){
  43. if(computer<22){
  44. cout << "You lose! Computer's cards:" << computer;
  45. }
  46. if(computer>21){
  47. cout << "You won! Computer's cards:" << computer;
  48. }
  49. }
  50. }
  51. }
  52. system ("pause>nul");
  53. return 0;
  54. }

Report this snippet  

You need to login to post a comment.