Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <iostream>
- #include <time.h>
- #include <stdlib.h>
- #include <string>
- using namespace std;
- // Hold the number of players
- int nPlays = 0;
- int nPlayers = 0;
- string *sPlayers;
- int *nPlayerBank;
- bool nPlayerBets[2][36];
- int result = 0;
- void ClearScreen()
- {
- cout << string( 100, '\n' );
- }
- void reset() {
- // Init the bets
- for(int i=0;i<nPlayers;i++) {
- for(int j=0;j<=36;j++) {
- nPlayerBets[i][j] = false;
- }
- }
- result = 0;
- nPlays++;
- ClearScreen();
- }
- void getbets() {
- // Ask each player how many bets they will make
- for(int i=0; i<nPlayers; i++) {
- cout << sPlayers[i] << ", how many bets would you like to place ($1 each): ";
- int nBets;
- cin >> nBets;
- // Get the bets now
- for(int j=0;j<nBets;j++) {
- cout << "Enter bet #" << j+1 << ": ";
- int nBet;
- cin >> nBet;
- nPlayerBets[i][nBet] = true;
- }
- }
- // Print the bets
- for(int i=0;i<nPlayers;i++) {
- cout << sPlayers[i] << " bet\n";
- for(int j=0;j<=36;j++) {
- if(nPlayerBets[i][j] == true) {
- cout << j << "\n";
- }
- }
- }
- }
- void spin() {
- // Spin the wheel!
- srand(time(NULL));
- result = rand() % 36;
- // No more bets!
- cout << "No more bets, please!\n";
- // Print the results
- cout << "******" << result << "******\n";
- }
- void checktable() {
- // See who won
- for(int i=0;i<nPlayers;i++) {
- if(nPlayerBets[i][result] == true) {
- cout << sPlayers[i] << " won!\n";
- int nBets = 0;
- for(int k=0;k<=36;k++) {
- if(nPlayerBets[i][k] == true) {
- nBets++;
- }
- }
- nPlayerBank[i] = ((nPlayerBank[i] - nBets) + 36);
- cout << sPlayers[i] << " has $" << nPlayerBank[i] << "!\n";
- }
- if(nPlayerBets[i][result] == false){
- int nBets = 0;
- for(int k=0;k<=36;k++) {
- if(nPlayerBets[i][k] == true) {
- nBets++;
- }
- }
- if(i>0) {
- nPlayerBank[i] = nPlayerBank[i] - (nBets - 1);
- cout << sPlayers[i] << " has $" << nPlayerBank[i] << "!\n";
- } else {
- nPlayerBank[i] = nPlayerBank[i] - (nBets);
- cout << sPlayers[i] << " has $" << nPlayerBank[i] << "!\n";
- }
- }
- }
- cout << "\n\n***Please type \"n\" then hit enter to continue***";
- while (1)
- {
- if ('n' == getchar())
- break;
- }
- }
- int main() {
- // Welcome and get number of players
- cout << "Welcome to roulette!\n";
- cout << "\nEnter number of players: ";
- cin >> nPlayers;
- // This will hold the player names
- sPlayers = new string[nPlayers];
- nPlayerBank = new int[nPlayers];
- reset();
- // Get player names
- for(int i=0; i<nPlayers; i++) {
- cout << "Enter name for player #" << i + 1 << ": ";
- cin >> sPlayers[i];
- }
- // Welcome and get cash
- for(int i=0; i <nPlayers; i++) {
- cout << "Welcome back " << sPlayers[i] << "\n";
- cout << "Please put your cash on the table: ";
- int getCash = 0;
- cin >> getCash;
- nPlayerBank[i] = getCash;
- cout << "Thank you " << sPlayers[i] << " you have $" << nPlayerBank[i] << " chips!\n";
- }
- for(;;) {
- getbets();
- spin();
- checktable();
- reset();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement