Advertisement
-MK-

12 check

Sep 29th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.69 KB | None | 0 0
  1. //============================================================================
  2. // Name        : 12.cpp
  3. // Author      :
  4. // Version     :
  5. // Copyright   : Your copyright notice
  6. // Description : Hello World in C++, Ansi-style
  7. //============================================================================
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. int printRounds();
  13.  
  14. int main() {
  15.     int round[] = {0, 0, 0};
  16.     int gameCountIn;
  17.     int gameCountSys = 0;
  18.     int gameSummary[] = {0, 0, 0};
  19.  
  20.     cin >> gameCountIn;
  21.  
  22.     do {
  23.         gameCountSys++;
  24.  
  25.         cout << "    *** GAME " << gameCountSys << "***\n"
  26.                 "Roll   Player 1    Player 2\n";
  27.  
  28.         switch(printRounds()) {
  29.         case 1:
  30.             cout << "\n\nPlayer one wins!\n\n";
  31.             gameSummary[0]++;
  32.             break;
  33.         case 2:
  34.             cout << "\n\nPlayer two wins!\n\n";
  35.             gameSummary[1]++;
  36.             break;
  37.         case 3:
  38.             cout << "\n\nIt's a tie!\n\n";
  39.             gameSummary[2]++;
  40.             break;
  41.         }
  42.     } while(gameCountIn != gameCountSys);
  43.  
  44.     cout << "  *** GAME SUMMARY ***\nPlayer 1   Player 2    Ties\n"
  45.          <<  " " << gameSummary[0] << " " << gameSummary[1] << "    "; gameSummary[2];
  46.  
  47.     return 0;
  48. }
  49.  
  50. int printRounds(int round[]) {  //will return who won
  51.  
  52.     round[0]++;
  53.     round[1] += rand() % 6 + 1;
  54.     round[2] += rand() % 6 + 1;
  55.  
  56.     cout << round[0] << "   " << round[1] << "  " << round[2] << endl;
  57.  
  58.     if (round[0] > 3) {             //In rounds after 3, there is a potential for a player to exceed 21
  59.         if (round[1] > 21) {
  60.             if (round[2] > 21) {
  61.                 return 3;           //tie
  62.             } else {
  63.                 return 2;           //1 wins
  64.             }
  65.         } else if (round[2] > 21) {
  66.             return 1;               //1 wins
  67.         } else if (round[1] == 21) {
  68.             return 1;               //1 wins
  69.         } else if (round[2] == 21) {
  70.             return 2;               //2 wins
  71.         }
  72.     }
  73.     printRounds();
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement