Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christian Ballard
- //COSC 1330 - 003
- //This will hopefully be a Roulette game.
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <Windows.h>
- #include <string>
- #include <conio.h>
- using namespace std;
- void welcome();
- double funBalance(double &);
- int funWinningIndex(int);
- void funTables(string tables[5][15]);
- double makeBet(double &);
- void numberBet(double &);
- void makeEvenMoneyBet(double &);
- void makeThirdBet(double &);
- void make2to1Bet(double &);
- void spin();
- void cashOutScreen(double);
- HANDLE console = GetStdHandle(STD_OUTPUT_HANDLE); // For use of SetConsoleTextAttribute()
- void WaitKey();
- int main()
- {
- double balance = 0;
- int random = 0;
- string tables[5][15] =
- { { "0", "3", "6", "9", "12", "15", "18", "21", "24", "27", "30", "33", "36", "2 to 1" },
- { "2", "5", "8", "11", "14", "17", "20", "23", "26", "29", "32", "35", "2 to 1" },
- { "1", "4", "7", "10", "13", "16", "19", "22", "25", "28", "31", "34", "2 to 1" },
- { "1st 12", "2nd 12", "3rd 12" },
- { "1-18", "Even", "Red", "Black", "Odd", "19-36" }};
- cout << fixed << setprecision(2);
- srand(static_cast<int>(time(0)));
- welcome();
- system("cls");
- balance = funBalance(balance);
- system("cls");
- cout << "Your current balance is $" << balance << endl;
- funTables(tables);
- cout << endl;
- makeBet(balance);
- system("pause");
- return 0;
- }
- void welcome()
- {
- int len = 0, x, y = 240;
- string text = "ROULETTE";
- len = text.length();
- cout << endl << endl << endl << "\t\t\t\t";
- for (x = 0; x<len; x++)
- {
- SetConsoleTextAttribute(console, y);
- cout << text[x];
- y++;
- if (y >254)
- y = 240;
- Sleep(250);
- }
- SetConsoleTextAttribute(console, 15);
- WaitKey();
- }
- double funBalance(double &balance)
- {
- cout << "How much money would you like to play at the table?" << endl << "$";
- cin >> balance;
- return balance;
- }
- int funWinningIndex()
- {
- int funWinningIndex = 0;
- funWinningIndex = 0 + rand() % (36 - 0 + 1);
- return funWinningIndex;
- }
- void funTables(string tables[5][15])
- {
- cout << "-==================================================================-" << endl;
- cout << "| || 3 | 6 | 9 | 12 | 15 | 18 | 21 | 24 | 27 | 30 | 33 | 36 || 2 |" << endl;
- cout << "| 0 | 2 | 5 | 8 | 11 | 14 | 17 | 20 | 23 | 26 | 29 | 32 | 35 | to |" << endl;
- cout << "| || 1 | 4 | 7 | 10 | 13 | 16 | 19 | 22 | 25 | 28 | 31 | 34 || 1 |" << endl;
- cout << "-==================================================================-" << endl;
- cout << " | First Twelve | Second Twelve | Third Twelve |" << endl;
- cout << " | 1 - 18 | Even | Red | Black | Odd | 19 - 36 |" << endl;
- cout << " -=============================================================-" << endl;
- }
- double makeBet(double &balance)
- {
- double newBalance = 0.0;
- int whatBet = 0;
- char anotherBet = ' ';
- do
- {
- cout << "Which type of bet would you like to make?" << endl << "1.) Number" << endl << "2.) Even Money" << endl << "3.) Third" << endl << "4.) 2 to 1" << endl << "5.) No more bets" << endl;
- cin >> whatBet;
- //switch for the bets
- switch (whatBet)
- {
- case 1:
- numberBet(balance);
- break;
- case 2:
- makeEvenMoneyBet(balance);
- break;
- case 3:
- makeThirdBet(balance);
- break;
- case 4:
- make2to1Bet(balance);
- break;
- case 5:
- system("cls");
- break;
- default:
- cout << "Invalid Input, please enter a number 1-5.";
- }
- cout << "Would you like to make another bet? (Y/N) ";
- cin >> anotherBet;
- toupper(anotherBet);
- } while (anotherBet == 'Y');
- {
- cout << "Thanks for playing!" << endl;
- cashOutScreen(balance);
- }
- return balance;
- }
- void numberBet(double &balance)
- {
- int selectedNumber = 0;
- double betAmount = 0.0;
- do
- {
- cout << "Please enter the number you would like to bet on: ";
- cin >> selectedNumber;
- if (selectedNumber <= 36 && selectedNumber >= 0)
- {
- {
- cout << "Enter the bet amount: ";
- cin >> betAmount;
- }
- }
- else
- {
- cout << "This number is not on the roulette table, please try again." << endl;
- }
- } while (selectedNumber >= 36 || selectedNumber <= 0); {
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 35;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- }
- }
- void makeEvenMoneyBet(double &balance)
- {
- double betAmount = 0.0;
- int typeOfEvenMoneyBet = 0;
- cout << "Which even money bet would you like to make?" << endl << "1.) 1 to 18" << endl << "2.) 19 to 36" << endl << "3.) Even" << endl << "4.) Odd" << endl << "5.) Red" << endl << "6.) Black" << endl;
- cin >> typeOfEvenMoneyBet;
- //Switch for the even money bets
- switch (typeOfEvenMoneyBet)
- {
- case 1:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 2;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 2:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 2;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 3:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 2;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 4:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 2;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 5:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 2;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 6:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 2;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- default:
- cout << "Invalid Input, please enter a number 1-6.";
- }
- }
- void makeThirdBet(double &balance)
- {
- double betAmount = 0.0;
- int typeOfThirdBet = 0;
- cout << "Which third would you like to bet on?" << endl << "1.) First 12" << endl << "2.) Second 12" << endl << "3.) Third 12" << endl;
- cin >> typeOfThirdBet;
- switch (typeOfThirdBet)
- {
- case 1:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 3;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 2:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 3;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- case 3:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 3;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- break;
- default:
- cout << "Invalid Input, please enter a number 1-3.";
- }
- }
- void make2to1Bet(double &balance)
- {
- double betAmount = 0.0;
- int typeOf2to1Bet = 0;
- cout << "Which section would you like to bet on?" << endl << "1.) Top Row" << endl << "2.) Middle Row" << endl << "3.) Bottom Row" << endl;
- cin >> typeOf2to1Bet;
- switch (typeOf2to1Bet)
- {
- case 1:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 3;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- case 2:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 3;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- case 3:
- cout << "Please enter the bet amount: $";
- cin >> betAmount;
- if (balance > betAmount && balance == funWinningIndex())
- {
- balance = betAmount * 3;
- }
- else if (balance != funWinningIndex())
- {
- cout << "Sorry you're a LOSER." << endl;
- balance = balance - betAmount;
- }
- else
- {
- cout << "Sorry, you don't have that much money." << endl;
- }
- default:
- cout << "Invalid Input, please enter a number 1-3.";
- }
- }
- void cashOutScreen(double balance)
- {
- system("cls");
- cout << "***************************************************" << endl;
- cout << "* *" << endl;
- cout << "* *" << endl;
- cout << "* *" << endl;
- cout << "* *" << endl;
- cout << "* Your payout is $" << balance << " *" << endl;
- cout << "* *" << endl;
- cout << "* *" << endl;
- cout << "* *" << endl;
- cout << "* *" << endl;
- cout << "***************************************************" << endl;
- }
- void WaitKey()
- {
- cout << endl << endl << endl << "\t\t\tPress any key";
- while (_kbhit()) _getch();
- _getch();
- while (_kbhit()) _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment