Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdlib.h>
- #include <ctime>
- using namespace std;
- // Global Variables
- // Matrix for case 1
- int redColours[] = {1, 3, 5, 7, 9, 12, 14, 16, 18, 19, 21, 23, 25, 27, 30, 32, 34, 36};
- int main()
- {
- srand(time(NULL));
- int counterOfRounds = 0;
- int roundsWon = 0;
- int roundsLost = 0;
- float moneyWonInRounds = 0; // It's for the money the user takes in THE ROUNDS HE WON
- float moneyLostInRounds = 0; // It's for the money the user loses in the ROUNDS HE LOST
- // 1. Intro - Rules
- cout << "Welcome to the famous CASINO GAME - THE ROULETTE !!!!" << endl;
- cout << "First, a few words about the game: " << endl;
- 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;
- cout << "B) Secondly, you have to decide about the kind of bet: " << endl;
- cout << " 1) You can bet in a colour (write red, black but NOT in the green colour(ONLY 0 IS GREEN))" << endl;
- cout << " 2) Bet in even/odds." << endl;
- cout << " 3) Bet either 1-18 or 19-36" << endl;
- cout << " 4) Bet in dozens: 1-12 or 13-24 or 25-36." << endl;
- cout << " 5) Bet in columns (1,4,7,.... or 2,5,8,.... or 3,6,9,....)." << endl;
- cout << " 6) Bet six numbers in row (1,2,3,4,5,6 or .... or 31,32,33,34,35,36)." << endl;
- cout << " 7) Bet four numbers in row." << endl;
- cout << " 8) Bet three numbers in row." << endl;
- cout << " 9) Bet two numbers in row." << endl;
- cout << " 10) Bet a single number." << endl << endl;
- // 2. Ask the user to give me how much money do you have
- cout << "\n\n****************************************************\n";
- cout << "First, give me how much money do you have?" << endl;
- cout << "Money: ";
- float money;
- cin >> money;
- while(money <= 0){
- cout << "Money: ";
- cin >> money;
- }
- cout << endl;
- while(money <= 0){
- cout << "Money: ";
- cin >> money;
- cout << endl;
- }
- cout << "****************************************************\n";
- cout << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- float initialMoney = money;
- // **** Here will be the CHECKPOINT FOR GOTO ****
- menu:
- counterOfRounds ++;
- cout << endl << " ROUND " << counterOfRounds << "\n";
- // 3. Ask the user to give me his bet
- cout << "\n\nNow, it's time to give me how much money are you gonna bet?" << endl;
- cout << "Bet: ";
- float bet;
- cin >> bet;
- while(bet <= 0 || bet > money){
- cout << "Bet: ";
- cin >> bet;
- }
- cout << endl;
- // 4. Create the random number of roulette
- int randomRouletteNumber = rand() % 37;
- // 5. After the creation of random number, I ask the user to select a category of bet
- cout << "Now, you have to select the category of your bet. The available numbers are shown above (1 to 10).\n";
- cout << "Check the number in front of the bet you want and type it!\n";
- int userBetOption;
- cin >> userBetOption;
- while(userBetOption <= 0 || userBetOption > 10){
- cin >> userBetOption;
- }
- // *******************************************************************************************************
- // *******************************************************************************************************
- // CASE 1- BET IN RED OR BLACK
- if(userBetOption == 1){
- cout << "You chose to bet by colour. Type 'red' or 'black'.\n";
- string colourSelected;
- cin >> colourSelected;
- if(colourSelected == "red" || colourSelected == "RED" || colourSelected == "Red"){
- cout << "\nYou bet **** " << bet << " **** money in the **** " << colourSelected << " **** colour.\n";
- bool isItRed = false;
- for(int i=0; i<sizeof(redColours)/sizeof(redColours[0]); i++){
- if(randomRouletteNumber == redColours[i]){
- isItRed = true; // Flag becomes true, if random number EXISTS in my list of red numbers
- }
- } // End of for
- cout << "Roulette ball stands in: " << randomRouletteNumber << endl;
- // New if-case to check the value of my flag
- if(isItRed == true){
- cout << "Nice! You won " << bet << " money with this bet." << endl;
- money += bet;
- roundsWon ++; // **** Extra ****
- moneyWonInRounds += bet; // **** Extra ****
- cout << "Your money now: " << money << endl;
- }
- else{
- cout << "Such a same! You lost " << bet << " money with this bet." << endl;
- money -= bet;
- roundsLost ++; // **** Extra ****
- moneyLostInRounds += bet; // **** Extra ****
- cout << "Your money now: " << money << endl;
- }
- // **** QUESTION to the user ****
- if(money == 0){
- goto exit;
- }
- else{
- cout << endl << "---> Do you want to continue betting?" << endl;
- string response;
- cin >> response;
- if(response == "yes" || response == "YES" || response == "Yes"){
- goto menu;
- }
- else if(response == "no" || response == "NO" || response == "No"){
- goto exit;
- }
- else{
- cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
- goto menu;
- }
- }
- } // END OF RED BET
- else if(colourSelected == "black" || colourSelected == "BLACK" || colourSelected == "Black"){
- cout << "\nYou bet **** " << bet << " **** money in the **** " << colourSelected << " **** colour.\n";
- bool isItRed = false;
- for(int i=0; i<sizeof(redColours)/sizeof(redColours[0]); i++){
- if(randomRouletteNumber == redColours[i]){
- isItRed = true; // Flag becomes true, if random number EXISTS in my list of red numbers
- }
- } // End of for
- cout << "Roulette ball stands in: " << randomRouletteNumber << endl;
- // New if-case to check the value of my flag
- if(isItRed == false){
- cout << "Nice! You won " << bet << " money with this bet." << endl;
- money += bet;
- roundsWon ++; // **** Extra ****
- moneyWonInRounds += bet; // **** Extra ****
- cout << "Your money now: " << money << endl;
- }
- else{
- cout << "Such a same! You lost " << bet << " money with this bet." << endl;
- money -= bet;
- roundsLost ++; // **** Extra ****
- moneyLostInRounds += bet; // **** Extra ****
- cout << "Your money now: " << money << endl;
- }
- // **** QUESTION to the user ****
- if(money == 0){
- goto exit;
- }
- else{
- cout << endl << "---> Do you want to continue betting?" << endl;
- string response;
- cin >> response;
- if(response == "yes" || response == "YES" || response == "Yes"){
- goto menu;
- }
- else if(response == "no" || response == "NO" || response == "No"){
- goto exit;
- }
- else{
- cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
- goto menu;
- }
- }
- } // END OF BLACK BET
- else{ // If the user typed WRONG WORD EXCEPT RED OR BLACK
- cout << colourSelected << " is not a colour in roulette! Invalid option....\n";
- cout << "Your money now: " << money << endl;
- // **** QUESTION to the user ****
- if(money == 0){
- goto exit;
- }
- else{
- cout << endl << "---> Do you want to continue betting?" << endl;
- string response;
- cin >> response;
- if(response == "yes" || response == "YES" || response == "Yes"){
- goto menu;
- }
- else if(response == "no" || response == "NO" || response == "No"){
- goto exit;
- }
- else{
- cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
- goto menu;
- }
- }
- }
- cout << endl;
- }
- // **** END OF CASE 1 ****
- // *******************************************************************************************************
- // *******************************************************************************************************
- // Case 2 - Even or odd numbers
- else if(userBetOption == 2){
- cout << "You chose to bet on even/odds. Type 'even' or 'odd'.\n";
- string evenOrOdd;
- cin >> evenOrOdd;
- if(evenOrOdd == "even" || evenOrOdd == "EVEN" || evenOrOdd == "Even"){
- cout << "\nYou bet **** " << bet << " **** money in the **** " << evenOrOdd << " **** numbers.\n";
- cout << "Roulette ball stands in: " << randomRouletteNumber << endl;
- if(randomRouletteNumber % 2 == 0 && randomRouletteNumber != 0){
- cout << "Nice! You won " << bet << " money with this bet.\n";
- money += bet;
- roundsWon ++; // **** Extra ****
- moneyWonInRounds += bet; // **** Extra ****
- cout << "Current money: " << money << endl;
- }
- else{
- cout << "Such a shame! You lost " << bet << " money with this bet.\n";
- money -= bet;
- roundsLost ++; // **** Extra ****
- moneyLostInRounds += bet; // **** Extra ****
- cout << "Current money: " << money << endl;
- }
- // **** QUESTION to the user ****
- if(money == 0){
- goto exit;
- }
- else{
- cout << endl << "---> Do you want to continue betting?" << endl;
- string response;
- cin >> response;
- if(response == "yes" || response == "YES" || response == "Yes"){
- goto menu;
- }
- else if(response == "no" || response == "NO" || response == "No"){
- goto exit;
- }
- else{
- cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
- goto menu;
- }
- }
- } // END OF EVEN BET
- else if(evenOrOdd == "odd" || evenOrOdd == "ODD" || evenOrOdd == "Odd"){
- cout << "\nYou bet **** " << bet << " **** money in the **** " << evenOrOdd << " **** numbers.\n";
- cout << "Roulette ball stands in: " << randomRouletteNumber << endl;
- if(randomRouletteNumber % 2 == 0 && randomRouletteNumber != 0){
- cout << "Such a shame! You lost " << bet << " money with this bet.\n";
- money -= bet;
- roundsLost ++; // **** Extra ****
- moneyLostInRounds += bet; // **** Extra ****
- cout << "Current money: " << money << endl;
- }
- else{
- cout << "Nice! You won " << bet << " money with this bet.\n";
- money += bet;
- roundsWon ++; // **** Extra ****
- moneyWonInRounds += bet; // **** Extra ****
- cout << "Current money: " << money << endl;
- }
- // **** QUESTION to the user ****
- if(money == 0){
- goto exit;
- }
- else{
- cout << endl << "---> Do you want to continue betting?" << endl;
- string response;
- cin >> response;
- if(response == "yes" || response == "YES" || response == "Yes"){
- goto menu;
- }
- else if(response == "no" || response == "NO" || response == "No"){
- goto exit;
- }
- else{
- cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
- goto menu;
- }
- }
- } // END OF ODD BET
- else{ // In case of invalid option from user
- cout << "That's not a valid option.... You wrote '" << evenOrOdd << "' instead of writing 'even' or 'odd'.\n";
- cout << "Current money: " << money << endl;
- // **** QUESTION to the user ****
- if(money == 0){
- goto exit;
- }
- else{
- cout << endl << "---> Do you want to continue betting?" << endl;
- string response;
- cin >> response;
- if(response == "yes" || response == "YES" || response == "Yes"){
- goto menu;
- }
- else if(response == "no" || response == "NO" || response == "No"){
- goto exit;
- }
- else{
- cout << "You didn't response with 'yes' or 'no' as I expected, but I'll consider that you are continuing!\n";
- goto menu;
- }
- }
- }
- cout << endl;
- }
- // **** End of CASE 2 ****
- exit:
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
- cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl << endl;
- // Check if the user won or lost money in casino while playing the roulette
- float gainOrLoss = money - initialMoney;
- cout << " S U M M A R Y " << endl;
- if(gainOrLoss > 0){
- cout << "Initial Money: " << initialMoney << endl;
- cout << " Money now : " << money << endl;
- cout << " Gain : +" << gainOrLoss << endl;
- }
- else if(gainOrLoss < 0){
- cout << "Initial Money: " << initialMoney << endl;
- cout << " Money now : " << money << endl;
- cout << " Loss : " << gainOrLoss << endl;
- }
- else{
- cout << "Initial Money: " << initialMoney << endl;
- cout << " Money now : " << money << endl;
- cout << " Gain/Loss : " << gainOrLoss << endl;
- }
- // Extra Statistics
- cout << "\nDo you want to see extra statistics of your performance today?\n";
- string answerForExtraStatistics;
- cin >> answerForExtraStatistics;
- if(answerForExtraStatistics == "yes" || answerForExtraStatistics == "YES" || answerForExtraStatistics == "Yes"){
- cout << endl << endl << " E X T R A S T A T I S T I C S\n";
- cout << "Rounds played: " << counterOfRounds << endl;
- cout << "Rounds won : " << roundsWon << "(" << 100 * roundsWon / counterOfRounds << "%)" << endl;
- cout << "Rounds lost : " << roundsLost << "(" << 100 * roundsLost / counterOfRounds << "%)" << endl;
- cout << "Money won : " << moneyWonInRounds << endl;
- cout << "Money lost : " << -moneyLostInRounds << endl;
- cout << "Gain/loss : " << moneyWonInRounds-moneyLostInRounds << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement