/* returns the number of memory locations user entered a value to */ int launch_shell(int memory[]) { printGreeting(); /* Read input, store in memory */ int user_input = 0; int i = 0; while ((user_input != -99999) && (i < MEMORY_SIZE)) { printf("%02d ? ", i); scanf("%d", &user_input); if (is_valid_input(user_input)) { memory[i] = user_input; ++i; } else if (user_input == -99999) { ; } else { puts("*** ERROR: acceptable range is from -9999 to 9999 ***"); } } return i; }
main() { int bet; int bank = 100; int i; int cardRank[5]; int cardSuit[5]; int finalRank[5]; int finalSuit[5]; int ranksinHand[13]; int suitsinHand[4]; int winnings; time_t t; char suit, rank, stillPlay; // This function is called outside of the do-while loop because the // greeting only needs to be displayed once, // while everything else in main will run multiple times, // depending on how many times the user wants to play. printGreeting(); // Loop runs each time the user plays a new hand of draw poker do { bet = getBet(); srand(time(&t)); getFirstHand(cardRank, cardSuit); printf("Your five cards: \n"); for (i=0; i<5; i++) { suit = getSuit(cardSuit[i]); rank = getRank(cardRank[i]); printf("Card #%d: %c%c\n", i+1, rank, suit); } // These two arrays are used to figure out the value of // the player's hand. However, they must be zeroed out // in case the user plays multiple hands. for (i=0; i<4; i++) { suitsinHand[i] = 0; } for (i=0; i<13; i++) { ranksinHand[i] = 0; } getFinalHand(cardRank, cardSuit, finalRank, finalSuit, ranksinHand, suitsinHand); printf("Your final five cards: \n"); for (i = 0; i < 5; i++) { suit = getSuit(finalSuit[i]); rank = getRank(finalRank[i]); printf("Card #%d: %c%c\n", i+1, rank, suit); } winnings = analyzeHand(ranksinHand, suitsinHand); printf("You won %d!\n", bet*winnings); bank = bank - bet + (bet*winnings); printf("\nYour bank is now %d.\n", bank); printf("\nDo you want to play again? "); scanf(" %c", &stillPlay); } while (toupper(stillPlay) == 'Y'); return 0; }