Advertisement
Guest User

Untitled

a guest
Feb 9th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.03 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include <string>
  6.  
  7. using namespace std;
  8.  
  9. // Hold the number of players
  10. int nPlays = 0;
  11. int nPlayers = 0;
  12. string *sPlayers;
  13. int *nPlayerBank;
  14. bool nPlayerBets[2][36];
  15. int result = 0;
  16.  
  17. void ClearScreen()
  18.   {
  19.   cout << string( 100, '\n' );
  20.   }
  21.  
  22.  
  23. void reset() {
  24.     // Init the bets
  25.     for(int i=0;i<nPlayers;i++) {
  26.         for(int j=0;j<=36;j++) {
  27.             nPlayerBets[i][j] = false;
  28.         }
  29.     }
  30.  
  31.     result = 0;
  32.     nPlays++;
  33.  
  34.     ClearScreen();
  35. }
  36.  
  37. void getbets() {
  38.     // Ask each player how many bets they will make
  39.     for(int i=0; i<nPlayers; i++) {
  40.         cout << sPlayers[i] << ", how many bets would you like to place ($1 each): ";
  41.         int nBets;
  42.         cin  >> nBets;
  43.  
  44.         // Get the bets now
  45.         for(int j=0;j<nBets;j++) {
  46.             cout << "Enter bet #" << j+1 << ": ";
  47.             int nBet;
  48.             cin  >> nBet;
  49.  
  50.             nPlayerBets[i][nBet] = true;
  51.         }
  52.     }
  53.  
  54.     // Print the bets
  55.     for(int i=0;i<nPlayers;i++) {
  56.         cout << sPlayers[i] << " bet\n";
  57.         for(int j=0;j<=36;j++) {
  58.             if(nPlayerBets[i][j] == true) {
  59.                 cout << j << "\n";
  60.             }
  61.         }
  62.     }
  63. }
  64.  
  65. void spin() {
  66.     // Spin the wheel!
  67.     srand(time(NULL));
  68.     result = rand() % 36;
  69.  
  70.     // No more bets!
  71.     cout << "No more bets, please!\n";
  72.  
  73.     // Print the results
  74.     cout << "******" << result << "******\n";
  75. }
  76.  
  77. void checktable() {
  78.     // See who won
  79.     for(int i=0;i<nPlayers;i++) {
  80.         if(nPlayerBets[i][result] == true) {
  81.             cout << sPlayers[i] << " won!\n";
  82.             int nBets = 0;
  83.  
  84.             for(int k=0;k<=36;k++) {
  85.                 if(nPlayerBets[i][k] == true) {
  86.                     nBets++;
  87.                 }
  88.             }
  89.  
  90.             nPlayerBank[i] = ((nPlayerBank[i] - nBets) + 36);
  91.  
  92.             cout << sPlayers[i] << " has $" << nPlayerBank[i] << "!\n";
  93.         }
  94.         if(nPlayerBets[i][result] == false){
  95.             int nBets = 0;
  96.  
  97.             for(int k=0;k<=36;k++) {
  98.                 if(nPlayerBets[i][k] == true) {
  99.                     nBets++;
  100.                 }
  101.             }
  102.  
  103.             if(i>0) {
  104.                 nPlayerBank[i] = nPlayerBank[i] - (nBets - 1);
  105.                 cout << sPlayers[i] << " has $" << nPlayerBank[i] << "!\n";
  106.             } else {
  107.                 nPlayerBank[i] = nPlayerBank[i] - (nBets);
  108.                 cout << sPlayers[i] << " has $" << nPlayerBank[i] << "!\n";
  109.             }
  110.         }
  111.     }
  112.  
  113.     cout << "\n\n***Please type \"n\" then hit enter to continue***";
  114.     while (1)
  115.     {
  116.         if ('n' == getchar())
  117.            break;
  118.     }
  119. }
  120.  
  121. int main() {
  122.     // Welcome and get number of players
  123.     cout << "Welcome to roulette!\n";
  124.     cout << "\nEnter number of players: ";
  125.     cin  >> nPlayers;
  126.  
  127.     // This will hold the player names
  128.     sPlayers    = new string[nPlayers];
  129.     nPlayerBank = new int[nPlayers];
  130.  
  131.     reset();
  132.  
  133.     // Get player names
  134.     for(int i=0; i<nPlayers; i++) {
  135.         cout << "Enter name for player #" << i + 1 << ": ";
  136.         cin  >> sPlayers[i];
  137.     }
  138.  
  139.     // Welcome and get cash
  140.     for(int i=0; i <nPlayers; i++) {
  141.         cout << "Welcome back " << sPlayers[i] << "\n";
  142.         cout << "Please put your cash on the table: ";
  143.         int getCash = 0;
  144.         cin  >> getCash;
  145.         nPlayerBank[i] = getCash;
  146.         cout << "Thank you " << sPlayers[i] << " you have $" << nPlayerBank[i] << " chips!\n";
  147.     }
  148.  
  149.     for(;;) {
  150.         getbets();
  151.         spin();
  152.         checktable();
  153.         reset();
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement