//This is no match dealer game int dealer_no_match() { int i, j, numbers[16], wager = -1, match = -1; printf("\n:::::: No Match Dealer ::::::\n"); printf("You can wager up to all of your credits\n"); printf("the dealer will deal out 16 random numbers between 0 and 99.\n"); printf("If There are no matches among them, you double your money\n\n"); if(player.credits == 0) { printf("You dont have any credits to wager\n"); return -1; } while(wager == -1) wager = take_wager(player.credits, 0); printf("\t\t::: Dealing out 16 random numbers :::\n"); for(i = 0; i < 16; i++) { numbers[i] = rand() % 100; printf("%2d\t", numbers[i]); if(i%8 == 7) printf("\n"); } for(i = 0; i < 15; i ++) { j = i + 1; while(j < 16) { if(numbers[i] == numbers[j]) match = numbers[i]; j++; } } if(match != -1) { printf("The dealer matched the number %d\n", match); printf("You lose %d credits\n", wager); player.credits -= wager; } else { printf("there were no matches, you win %d credits\n", wager); player.credits += wager; } return 0; }
// This is the No Match Dealer game. // It returns -1 if the player has 0 credits. int dealer_no_match() { int i, j, numbers[16], wager = -1, match = -1; printf("\n::::::: No Match Dealer :::::::\n"); printf("In this game, you can wager up to all of your credits.\n"); printf("The dealer will deal out 16 random numbers between 0 and 99.\n"); printf("If there are no matches among them, you double your money!\n\n"); if(player.credits == 0) { printf("You don't have any credits to wager!\n\n"); return -1; } while(wager == -1) wager = take_wager(player.credits, 0); printf("\t\t::: Dealing out 16 random numbers :::\n"); for(i=0; i < 16; i++) { numbers[i] = rand() % 100; // pick a number 0 to 99 printf("%2d\t", numbers[i]); if(i%8 == 7) // Print a line break every 8 numbers. printf("\n"); } for(i=0; i < 15; i++) { // Loop looking for matches j = i + 1; while(j < 16) { if(numbers[i] == numbers[j]) match = numbers[i]; j++; } } if(match != -1) { printf("The dealer matched the number %d!\n", match); printf("You lose %d credits.\n", wager); player.credits -= wager; } else { printf("There were no matches! You win %d credits!\n", wager); player.credits += wager; } return 0; }
// This is the Find the Ace game. // It returns -1 if the player has 0 credits. int find_the_ace() { int i, ace, total_wager; int invalid_choice, pick = -1, wager_one = -1, wager_two = -1; char choice_two, cards[3] = {'X', 'X', 'X'}; ace = rand()%3; // Place the ace randomly. printf("******* Find the Ace *******\n"); printf("In this game, you can wager up to all of your credits.\n"); printf("Three cards will be dealt out, two queens and one ace.\n"); printf("If you find the ace, you will win your wager.\n"); printf("After choosing a card, one of the queens will be revealed.\n"); printf("At this point, you may either select a different card or\n"); printf("increase your wager.\n\n"); if(player.credits == 0) { printf("You don't have any credits to wager!\n\n"); return -1; } while(wager_one == -1) // Loop until valid wager is made. wager_one = take_wager(player.credits, 0); print_cards("Dealing cards", cards, -1); pick = -1; while((pick < 1) || (pick > 3)) { // Loop until valid pick is made. printf("Select a card: 1, 2, or 3 "); scanf("%d", &pick); } pick--; // Adjust the pick since card numbering starts at 0. i=0; while(i == ace || i == pick) // Keep looping until i++; // we find a valid queen to reveal. cards[i] = 'Q'; print_cards("Revealing a queen", cards, pick); invalid_choice = 1; while(invalid_choice) { // Loop until valid choice is made. printf("Would you like to:\n[c]hange your pick\tor\t[i]ncrease your wager?\n"); printf("Select c or i: "); choice_two = '\n'; while(choice_two == '\n') // Flush extra newlines. scanf("%c", &choice_two); if(choice_two == 'i') { // Increase wager. invalid_choice=0; // This is a valid choice. while(wager_two == -1) // Loop until valid second wager is made. wager_two = take_wager(player.credits, wager_one); } if(choice_two == 'c') { // Change pick. i = invalid_choice = 0; // Valid choice while(i == pick || cards[i] == 'Q') // Loop until the other card i++; // is found, pick = i; // and then swap pick. printf("Your card pick has been changed to card %d\n", pick+1); } } for(i=0; i < 3; i++) { // Reveal all of the cards. if(ace == i) cards[i] = 'A'; else cards[i] = 'Q'; } print_cards("End result", cards, pick); if(pick == ace) { // Handle win. printf("You have won %d credits from your first wager\n", wager_one); player.credits += wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager!\n", wager_two); player.credits += wager_two; } } else { // Handle loss. printf("You have lost %d credits from your first wager\n", wager_one); player.credits -= wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager!\n", wager_two); player.credits -= wager_two; } } return 0; }
//This is the find the ace game int find_the_ace() { int i, ace, total_wager; int invalid_choice, pick = -1, wager_one = -1, wager_two = -1; char choice_two, cards[3] = {'X', 'X', 'X'}; ace = rand()%3; printf("****** Find the ACE ******\n"); printf("In this game you can wager up to all of your credits\n"); printf("three cards will be dealt out, two queens and one ace\n"); printf("if you find the ace, you will win your wager\n"); printf("after choosing a card, one of the queens will be revealed\n"); printf("at this point, you may either select a different card or increase your wager\n\n"); if(player.credits == 0) { printf("you dont have enough credits\n\n"); return -1; } while(wager_one == -1) wager_one = take_wager(player.credits, 0); print_cards("dealing cards", cards, -1); pick = -1; while((pick < 1) || (pick > 3)) { printf("select a card: 1, 2, or 3 "); scanf("%d", &pick); } pick--; i = 0; while(i == ace || i == pick) { i++; } cards[i] = 'Q'; print_cards("Revealing a queen", cards, pick); invalid_choice = 1; while(invalid_choice) { printf("would you like to:\n[c]hange your pick\tor\t[i]ncrese your wager?\n"); printf("Select c or i; "); choice_two = '\n'; while(choice_two == '\n') scanf("%c", &choice_two); if(choice_two == 'i') { invalid_choice = 0; while(wager_two == -1) wager_two = take_wager(player.credits, wager_one); } if(choice_two == 'c') { i = invalid_choice = 0; while(i == pick || cards[i] == 'Q') i ++; pick = i; printf("Your card pick has been changed to card %d\n", pick + 1); } } for(i = 0; i < 3; i++) { if(ace == i) cards[i] = 'A'; else cards[i] = 'Q'; } print_cards("End Result", cards, pick); if(pick == ace) { printf("You have won %d credits from your first wager\n", wager_one); player.credits += wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager\n", wager_two); player.credits += wager_two; } } else { printf("you have lost %d credits from your first wager\n", wager_one); player.credits -= wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager\n", wager_two); player.credits -= wager_two; } } return 0; }
int find_the_ace(int credits) { int i = 0; int ace = rand() % 3; int total_wager; int invalid_choice = 1; int pick = -1; int wager_one = -1; int wager_two = -1; char choice_two = '\n'; char cards[3] = { 'X','X','X' }; printf("***FIND-THE-ACE***\n"); if (credits <= 0) { printf("You do not have any credits to wager!"); return -1; } while (wager_one == -1) wager_one = take_wager(credits, 0); print_cards("Dealing cards", cards, -1); while (pick < 1 || pick > 3) { printf("Select a card: 1, 2 or 3 "); scanf_s("%d", &pick); } --pick; while (i == ace || i == pick) ++i; cards[i] = 'Q'; print_cards("Revealing a queen", cards, pick); while (invalid_choice) { printf("would you like to:\n[c]hange your pick\tot\t[i]ncrease your wager?\n"); printf("Select c or i :"); while (choice_two == '\n') scanf_s("%c", &choice_two); if (choice_two == 'i') { invalid_choice = 0; while (wager_two < 0) wager_two = take_wager(credits, wager_one); } if (choice_two == 'c') { invalid_choice = 0; i = 0; while (i == pick || cards[i] == 'Q')++i; pick = i; printf("Your card pick was changed to card %d\n", pick + 1); } choice_two = '\n'; } for (i = 0; i < 3; ++i) { if (ace == i) cards[i] = 'A'; else cards[i] = 'Q'; } print_cards("End Result", cards, pick); if (pick == ace) { printf("You have won %d credits from your first wager\n", wager_one); credits += wager_one; if (wager_two > 0) { printf("and additional %d credits from your second wager!\n", wager_two); credits += wager_two; } } else { printf("You have lost %d credits from your first wager\n", wager_one); credits -= wager_one; if (wager_two > 0) { printf("and additional %d credits from your second wager!\n", wager_two); credits -= wager_two; } } return credits; }