Advertisement
makispaiktis

ROULETTE

Aug 2nd, 2019 (edited)
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 16.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <ctime>
  4.  
  5. using namespace std;
  6.  
  7.  
  8. // Global Variables
  9. // Matrix for case 1
  10. int redColours[] = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36};
  11.  
  12. int main()
  13. {
  14.     srand(time(NULL));
  15.     int counterOfRounds = 0;
  16.     int roundsWon = 0;
  17.     int roundsLost = 0;
  18.     float moneyWonInRounds = 0;         // It's for the money the user takes in THE ROUNDS HE WON
  19.     float moneyLostInRounds = 0;        // It's for the money the user loses in the ROUNDS HE LOST
  20.  
  21.     // 1. Intro - Rules
  22.     cout << "Welcome to the famous CASINO GAME - THE ROULETTE !!!!" << endl;
  23.     cout << "First, a few words about the game: " << endl;
  24.     cout << "A) First, you have to tell me how much money you have and give me your bet (value in euros). There are numbers from 1 to 36 and the 0." << endl;
  25.     cout << "B) Secondly, you have to decide about the kind of bet: " << endl;
  26.     cout << "   1) You can bet in a colour (write red, black but NOT in the green colour(ONLY 0 IS GREEN))" << endl;
  27.     cout << "   2) Bet in even/odds." << endl;
  28.     cout << "   3) Bet either 1-18 or 19-36" << endl;
  29.     cout << "   4) Bet in dozens: 1-12 or 13-24 or 25-36." << endl;
  30.     cout << "   5) Bet in columns (1,4,7,....  or  2,5,8,....  or  3,6,9,....)." << endl;
  31.     cout << "   6) Bet six numbers in row (1,2,3,4,5,6  or  ....  or  31,32,33,34,35,36)." << endl;
  32.     cout << "   7) Bet four numbers in row." << endl;
  33.     cout << "   8) Bet three numbers in row." << endl;
  34.     cout << "   9) Bet two numbers in row." << endl;
  35.     cout << "  10) Bet a single number." << endl << endl;
  36.  
  37.  
  38.  
  39.  
  40.  
  41.     // 2. Ask the user to give me how much money do you have
  42.     cout << "\n\n****************************************************\n";
  43.     cout << "First,  give me how much money do you have?" << endl;
  44.     cout << "Money: ";
  45.     float money;
  46.     cin >> money;
  47.     while(money <= 0){
  48.         cout << "Money: ";
  49.         cin >> money;
  50.     }
  51.     cout << endl;
  52.     while(money <= 0){
  53.         cout << "Money: ";
  54.         cin >> money;
  55.         cout << endl;
  56.     }
  57.     cout << "****************************************************\n";
  58.     cout << endl;
  59.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  60.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  61.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  62.     float initialMoney = money;
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71. // **** Here will be the CHECKPOINT FOR GOTO ****
  72. menu:
  73.     counterOfRounds ++;
  74.     cout << endl << "                    ROUND " << counterOfRounds << "\n";
  75.     // 3. Ask the user to give me his bet
  76.     cout << "\n\nNow, it's time to give me how much money are you gonna bet?" << endl;
  77.     cout << "Bet: ";
  78.     float bet;
  79.     cin >> bet;
  80.     while(bet <= 0 || bet > money){
  81.         cout << "Bet: ";
  82.         cin >> bet;
  83.     }
  84.     cout << endl;
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.     // 4. Create the random number of roulette
  92.     int randomRouletteNumber = rand() % 37;
  93.     // 5. After the creation of random number, I ask the user to select a category of bet
  94.     cout << "Now, you have to select the category of your bet. The available numbers are shown above (1 to 10).\n";
  95.     cout << "Check the number in front of the bet you want and type it!\n";
  96.     int userBetOption;
  97.     cin >> userBetOption;
  98.     while(userBetOption <= 0 || userBetOption > 10){
  99.         cin >> userBetOption;
  100.     }
  101.  
  102.  
  103.  
  104.  
  105.     // *******************************************************************************************************
  106.     // *******************************************************************************************************
  107.     // CASE 1- BET IN RED OR BLACK
  108.     if(userBetOption == 1){
  109.         cout << "You chose to bet by colour. Type 'red' or 'black'.\n";
  110.         string colourSelected;
  111.         cin >> colourSelected;
  112.  
  113.         if(colourSelected == "red" || colourSelected == "RED" || colourSelected == "Red"){
  114.             cout << "\nYou bet **** " << bet << " **** money in the **** " << colourSelected << " **** colour.\n";
  115.             bool isItRed = false;
  116.             for(int i=0; i<sizeof(redColours)/sizeof(redColours[0]); i++){
  117.                 if(randomRouletteNumber == redColours[i]){
  118.                     isItRed = true;                     // Flag becomes true, if random number EXISTS in my list of red numbers
  119.                 }
  120.             } // End of for
  121.  
  122.             cout << "Roulette ball stands in:   " << randomRouletteNumber << endl;
  123.             //  New if-case to check the value of my flag
  124.             if(isItRed == true){
  125.                 cout << "Nice! You won " << bet << " money with this bet." << endl;
  126.                 money += bet;
  127.                 roundsWon ++;                       // **** Extra ****
  128.                 moneyWonInRounds += bet;            // **** Extra ****
  129.                 cout << "Your money now:  " << money << endl;
  130.             }
  131.             else{
  132.                 cout << "Such a same! You lost " << bet << " money with this bet." << endl;
  133.                 money -= bet;
  134.                 roundsLost ++;                       // **** Extra ****
  135.                 moneyLostInRounds += bet;            // **** Extra ****
  136.                 cout << "Your money now:  " << money << endl;
  137.             }
  138.  
  139.             // **** QUESTION to the user ****
  140.             if(money == 0){
  141.                 goto exit;
  142.             }
  143.             else{
  144.                 cout << endl << "---> Do you want to continue betting?" << endl;
  145.                 string response;
  146.                 cin >> response;
  147.                 if(response == "yes" || response == "YES" || response == "Yes"){
  148.                     goto menu;
  149.                 }
  150.                 else if(response == "no" || response == "NO" || response == "No"){
  151.                     goto exit;
  152.                 }
  153.                 else{
  154.                     cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
  155.                     goto menu;
  156.                 }
  157.             }
  158.  
  159.         } // END OF RED BET
  160.  
  161.         else if(colourSelected == "black" || colourSelected == "BLACK" || colourSelected == "Black"){
  162.             cout << "\nYou bet **** " << bet << " **** money in the **** " << colourSelected << " **** colour.\n";
  163.             bool isItRed = false;
  164.             for(int i=0; i<sizeof(redColours)/sizeof(redColours[0]); i++){
  165.                 if(randomRouletteNumber == redColours[i]){
  166.                     isItRed = true;                     // Flag becomes true, if random number EXISTS in my list of red numbers
  167.                 }
  168.             } // End of for
  169.  
  170.             cout << "Roulette ball stands in:   " << randomRouletteNumber << endl;
  171.             //  New if-case to check the value of my flag
  172.             if(isItRed == false){
  173.                 cout << "Nice! You won " << bet << " money with this bet." << endl;
  174.                 money += bet;
  175.                 roundsWon ++;                       // **** Extra ****
  176.                 moneyWonInRounds += bet;            // **** Extra ****
  177.                 cout << "Your money now:  " << money << endl;
  178.             }
  179.             else{
  180.                 cout << "Such a same! You lost " << bet << " money with this bet." << endl;
  181.                 money -= bet;
  182.                 roundsLost ++;                       // **** Extra ****
  183.                 moneyLostInRounds += bet;            // **** Extra ****
  184.                 cout << "Your money now:  " << money << endl;
  185.             }
  186.  
  187.             // **** QUESTION to the user ****
  188.             if(money == 0){
  189.                 goto exit;
  190.             }
  191.             else{
  192.                 cout << endl << "---> Do you want to continue betting?" << endl;
  193.                 string response;
  194.                 cin >> response;
  195.                 if(response == "yes" || response == "YES" || response == "Yes"){
  196.                     goto menu;
  197.                 }
  198.                 else if(response == "no" || response == "NO" || response == "No"){
  199.                     goto exit;
  200.                 }
  201.                 else{
  202.                     cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
  203.                     goto menu;
  204.                 }
  205.             }
  206.  
  207.         } // END OF BLACK BET
  208.  
  209.         else{               // If the user typed WRONG WORD EXCEPT RED OR BLACK
  210.             cout << colourSelected << " is not a colour in roulette! Invalid option....\n";
  211.             cout << "Your money now: " << money << endl;
  212.  
  213.             // **** QUESTION to the user ****
  214.             if(money == 0){
  215.                 goto exit;
  216.             }
  217.             else{
  218.                 cout << endl << "---> Do you want to continue betting?" << endl;
  219.                 string response;
  220.                 cin >> response;
  221.                 if(response == "yes" || response == "YES" || response == "Yes"){
  222.                     goto menu;
  223.                 }
  224.                 else if(response == "no" || response == "NO" || response == "No"){
  225.                     goto exit;
  226.                 }
  227.                 else{
  228.                     cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
  229.                     goto menu;
  230.                 }
  231.             }
  232.         }
  233.  
  234.         cout << endl;
  235.     }
  236.         // **** END OF CASE 1 ****
  237.  
  238.  
  239.  
  240.  
  241.     // *******************************************************************************************************
  242.     // *******************************************************************************************************
  243.     // Case 2 - Even or odd numbers
  244.     else if(userBetOption == 2){
  245.         cout << "You chose to bet on even/odds. Type 'even' or 'odd'.\n";
  246.         string evenOrOdd;
  247.         cin >> evenOrOdd;
  248.  
  249.         if(evenOrOdd == "even" || evenOrOdd == "EVEN" || evenOrOdd == "Even"){
  250.             cout << "\nYou bet **** " << bet << " **** money in the **** " << evenOrOdd << " **** numbers.\n";
  251.             cout << "Roulette ball stands in:   " << randomRouletteNumber << endl;
  252.             if(randomRouletteNumber % 2 == 0 && randomRouletteNumber != 0){
  253.                 cout << "Nice! You won " << bet << " money with this bet.\n";
  254.                 money += bet;
  255.                 roundsWon ++;                       // **** Extra ****
  256.                 moneyWonInRounds += bet;            // **** Extra ****
  257.                 cout << "Current money: " << money << endl;
  258.             }
  259.             else{
  260.                 cout << "Such a shame! You lost " << bet << " money with this bet.\n";
  261.                 money -= bet;
  262.                 roundsLost ++;                       // **** Extra ****
  263.                 moneyLostInRounds += bet;            // **** Extra ****
  264.                 cout << "Current money: " << money << endl;
  265.             }
  266.  
  267.             // **** QUESTION to the user ****
  268.             if(money == 0){
  269.                 goto exit;
  270.             }
  271.             else{
  272.                 cout << endl << "---> Do you want to continue betting?" << endl;
  273.                 string response;
  274.                 cin >> response;
  275.                 if(response == "yes" || response == "YES" || response == "Yes"){
  276.                     goto menu;
  277.                 }
  278.                 else if(response == "no" || response == "NO" || response == "No"){
  279.                     goto exit;
  280.                 }
  281.                 else{
  282.                     cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
  283.                     goto menu;
  284.                 }
  285.         }
  286.  
  287.         } // END OF EVEN BET
  288.  
  289.         else if(evenOrOdd == "odd" || evenOrOdd == "ODD" || evenOrOdd == "Odd"){
  290.             cout << "\nYou bet **** " << bet << " **** money in the **** " << evenOrOdd << " **** numbers.\n";
  291.             cout << "Roulette ball stands in:   " << randomRouletteNumber << endl;
  292.             if(randomRouletteNumber % 2 == 0 && randomRouletteNumber != 0){
  293.                 cout << "Such a shame! You lost " << bet << " money with this bet.\n";
  294.                 money -= bet;
  295.                 roundsLost ++;                       // **** Extra ****
  296.                 moneyLostInRounds += bet;            // **** Extra ****
  297.                 cout << "Current money: " << money << endl;
  298.             }
  299.             else{
  300.                 cout << "Nice! You won " << bet << " money with this bet.\n";
  301.                 money += bet;
  302.                 roundsWon ++;                       // **** Extra ****
  303.                 moneyWonInRounds += bet;            // **** Extra ****
  304.                 cout << "Current money: " << money << endl;
  305.             }
  306.  
  307.             // **** QUESTION to the user ****
  308.             if(money == 0){
  309.                 goto exit;
  310.             }
  311.             else{
  312.                 cout << endl << "---> Do you want to continue betting?" << endl;
  313.                 string response;
  314.                 cin >> response;
  315.                 if(response == "yes" || response == "YES" || response == "Yes"){
  316.                     goto menu;
  317.                 }
  318.                 else if(response == "no" || response == "NO" || response == "No"){
  319.                     goto exit;
  320.                 }
  321.                 else{
  322.                     cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
  323.                     goto menu;
  324.                 }
  325.         }
  326.  
  327.         } // END OF ODD BET
  328.  
  329.         else{                       // In case of invalid option from user
  330.             cout << "That's not a valid option.... You wrote '" << evenOrOdd << "' instead of writing 'even' or 'odd'.\n";
  331.             cout << "Current money: " << money << endl;
  332.  
  333.             // **** QUESTION to the user ****
  334.             if(money == 0){
  335.                 goto exit;
  336.             }
  337.             else{
  338.                 cout << endl << "---> Do you want to continue betting?" << endl;
  339.                 string response;
  340.                 cin >> response;
  341.                 if(response == "yes" || response == "YES" || response == "Yes"){
  342.                     goto menu;
  343.                 }
  344.                 else if(response == "no" || response == "NO" || response == "No"){
  345.                     goto exit;
  346.                 }
  347.                 else{
  348.                     cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
  349.                     goto menu;
  350.                 }
  351.                 }
  352.         }
  353.  
  354.         cout << endl;
  355.     }
  356.     // **** End of CASE 2 ****
  357.  
  358.  
  359.  
  360. exit:
  361.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  362.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
  363.     cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;
  364.  
  365.     // Check if the user won or lost money in casino while playing the roulette
  366.     float gainOrLoss = money - initialMoney;
  367.     cout << "                   S U M M A R Y " << endl;
  368.     if(gainOrLoss > 0){
  369.         cout << "Initial Money: " << initialMoney << endl;
  370.         cout << "  Money now  : " << money << endl;
  371.         cout << "    Gain     : +" << gainOrLoss << endl;
  372.     }
  373.     else if(gainOrLoss < 0){
  374.         cout << "Initial Money: " << initialMoney << endl;
  375.         cout << "  Money now  : " << money << endl;
  376.         cout << "    Loss     : " << gainOrLoss << endl;
  377.     }
  378.     else{
  379.         cout << "Initial Money: " << initialMoney << endl;
  380.         cout << "  Money now  : " << money << endl;
  381.         cout << "  Gain/Loss     : " << gainOrLoss << endl;
  382.     }
  383.  
  384.     // Extra Statistics
  385.     cout << "\nDo you want to see extra statistics of your performance today?\n";
  386.     string answerForExtraStatistics;
  387.     cin >> answerForExtraStatistics;
  388.     if(answerForExtraStatistics == "yes" || answerForExtraStatistics == "YES" || answerForExtraStatistics == "Yes"){
  389.         cout << endl << endl << "   E X T R A   S T A T I S T I C S\n";
  390.         cout << "Rounds played: " << counterOfRounds << endl;
  391.         cout << "Rounds won   : " << roundsWon << "(" << 100 * roundsWon / counterOfRounds << "%)" << endl;
  392.         cout << "Rounds lost  : " << roundsLost << "(" << 100 * roundsLost / counterOfRounds << "%)" << endl;
  393.         cout << "Money won    : " << moneyWonInRounds << endl;
  394.         cout << "Money lost   : " << -moneyLostInRounds << endl;
  395.         cout << "Gain/loss    : " << moneyWonInRounds-moneyLostInRounds << endl;
  396.     }
  397.  
  398.  
  399.     return 0;
  400. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement