Hello everyone! I'm new to the forums. I've searched Google to no end, and I'm at a loss at what to do. I usually try to figure things out on my own, but I'm just struggling something fierce so I come asking for help.
I'm working on a slot machine. There needs to be a three wheel & four wheel machine option. I'm working on two different concepts to receive the same output for each wheel (beats having several copies of the same console).
I cannot figure out how to do the if/else if/else statement for the random payout options. I can do it just fine if I use JUST numbers, but since I am forced to use the output of words (star, star, star - etc.), I'm just at a standstill on how to proceed.
In this code, I'm currently working under the void four() function, and everything is far from perfect. Trust me, I know that. In this function, it only prints out BAR - BAR - BAR. As you can see, listed in the payout table... that's the outputs I need. I just don't know how to proceed. I've tried arrays. I've tried switch statements. I've tried enumerations (and got absolutely nowhere with that).
Pretty sure there's something I'm overlooking and it's so stinkin' simple. But right now, I'm just fried and desperate. Everything I've seen on other forums is for a 3x3 grid and I don't need that. Just simple 3x anything, 2x + 1 of anything, and straight up loser.
Any help would be appreciated. (As an aside, I posted this on DaniWeb a few days ago - I don't know the protocol for cross posting).
Code:#include <iostream> #include <iomanip> #include <string> #include <ctime> #include <cstdlib> using namespace std; int credits = 50; int bet = 0; string slotLabels; // fruit names int slotFruits; // fruits string wheel1; string wheel2; string wheel3; void menu(char decision); void earnings(); void three(); // for three wheel slot machine. void four(); // for four wheel slot machine. int main() { srand(unsigned(time(NULL))); char pay = 0; char decision; cout << "WELCOME TO THE BOOGIE DOWN SLOT MACHINE!\n\n"; cout << "'3' - start the three wheel slot machine.\n" "'4' - start the four wheel slot machine.\n" "'T' - access the pay table.\n" "'P' - collect your earnings & cash out.\n" "'Q' - quit the game.\n" << endl; cout << "Let's play! What would you like to do? "; cin >> decision; cout << endl; cout << endl; menu(decision); return 0; } // FUNCTION FOR THE MAIN MENU DECISIONS // void menu(char decision) { // DECISION FOR THE TABLE PAYOUT ("T") // if (decision == 'T') { cout << "THREE WHEEL SLOT MACHINE: FOUR WHEEL SLOT MACHINE: PAYOUT:\n"; cout << "STAR - STAR - STAR STAR - STAR - STAR - STAR 1,000 COINS\n"; cout << "BAR - BAR - BAR BAR - BAR - BAR - BAR 500 COINS\n"; cout << "SEVEN - SEVEN - SEVEN SEVEN - SEVEN - SEVEN - SEVEN 250 COINS\n"; cout << "BAR - BAR - ANY BAR - BAR - BAR - ANY 100 COINS\n"; cout << "PLUM - PLUM - PLUM PLUM - PLUM - PLUM - PLUM 75 COINS\n"; cout << "LEMON - LEMON - LEMON LEMON - LEMON - LEMON - LEMON 50 COINS\n"; cout << "CHERRY - CHERRY - ANY CHERRY - CHERRY - ANY - ANY 25 COINS\n"; cout << "CHERRY - ANY - ANY CHERRY - ANY - ANY - ANY 5 COINS\n" << endl; } // DECISION TO START THE THREE WHEEL SLOT MACHINE ("3") // if (decision == '3') { three(); } // DECISION TO START THE FOUR WHEEL SLOT MACHINE ("4") // if (decision == '4') { four(); } // DECISION TO CASH OUT CREDITS // if (decision == 'P') { if (credits > 0) { cout << "You've cashed out " << credits << "!" << endl; credits = 0; } menu(decision); } } // FUNCTION TO START THE THREE WHEEL SLOT MACHINE // void three() { int wheel1, wheel2, wheel3; wheel1 = (rand() % 6) + 1; wheel2 = (rand() % 6) + 1; wheel3 = (rand() % 6) + 1; cout << "You currently have " << credits << " credits." << endl; cout << "How many of those credits would you like to bet? "; cin >> bet; cout << endl; // switch statement for the first wheel switch (wheel1) { case 1: cout << "STAR -" << " "; break; case 2: cout << "BAR -" << " "; break; case 3: cout << "SEVEN -" << " "; break; case 4: cout << "PLUM -" << " "; break; case 5: cout << "LEMON -" << " "; break; case 6: cout << "CHERRY -" << " "; break; } // switch statement for the second wheel switch (wheel2) { case 1: cout << "STAR -" << " "; break; case 2: cout << "BAR -" << " "; break; case 3: cout << "SEVEN -" << " "; break; case 4: cout << "PLUM -" << " "; break; case 5: cout << "LEMON -" << " "; break; case 6: cout << "CHERRY -" << " "; break; } // switch statement for wheel three switch (wheel3) { case 1: cout << "STAR -" << " "; break; case 2: cout << "BAR -" << " "; break; case 3: cout << "SEVEN -" << " "; break; case 4: cout << "PLUM -" << " "; break; case 5: cout << "LEMON -" << " "; break; case 6: cout << "CHERRY -" << " "; break; } if (wheel1 == 1 && wheel2 == 1 && wheel3 == 1) // THREE STARS (1,000) { credits = credits - bet; cout << "JACKPOT! You won 1,000 credits." << endl; cout << "You currently have " << credits + 1000 << " credits." << endl; } else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 2) // THREE BARS (500) { credits = credits - bet; cout << "AMAZING! You won 500 credits." << endl; cout << "You currently have " << credits + 500 << " credits." << endl; } else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 2) // THREE SEVENS (250) { credits = credits - bet; cout << "AWESOME! You won 250 credits." << endl; cout << "You currently have " << credits + 250 << " credits." << endl; } else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 0) // TWO BARS & ANYTHING (100) - How do I get it to random one of the others?! { credits = credits - bet; cout << "NICE! You won 100 credits." << endl; cout << "You currently have " << credits + 100 << " credits." << endl; } else if (wheel1 == 4 && wheel2 == 4 && wheel3 == 4) // THREE PLUMS (75) { credits = credits - bet; cout << "GOOD JOB! You won 75 credits." << endl; cout << "You currently have " << credits + 75 << " credits." << endl; } else if (wheel1 == 5 && wheel2 == 5 && wheel3 == 5) // THREE LEMONS (50) { credits = credits - bet; cout << "GOOD JOB! You won 50 credits." << endl; cout << "You currently have " << credits + 50 << " credits." << endl; } else if (wheel1 == 6 && wheel2 == 6 && wheel3 == 0) // TWO CHERRIES & ANYTHING (25) { credits = credits - bet; cout << "GOOD JOB! You won 25 credits." << endl; cout << "You currently have " << credits + 25 << " credits." << endl; } else if (wheel1 == 6 && wheel2 == 0 && wheel3 == 0) // ONE CHERRY & TWO ANYTHING (5) { credits = credits - bet; cout << "GOOD JOB! You won 5 credits." << endl; cout << "You currently have " << credits + 5 << " credits." << endl; } } // FUNCTION TO START THE FOUR WHEEL SLOT MACHINE // void four() { int STAR = 1; int BAR = 2; int SEVEN = 3; int PLUM = 4; int LEMON = 5; int CHERRY = 6; int wheel1; int wheel2; int wheel3; cout << "You have " << credits << " credits." << endl; cout << "How much would you like to bet? "; cin >> bet; credits = credits - bet; wheel1 = (rand() % 6) + 1; wheel2 = (rand() % 6) + 1; wheel3 = (rand() % 6) + 1; if (wheel1 == wheel2 == wheel3) { cout << "STAR - STAR - STAR" << endl << endl; cout << "JACKPOT! You won 1,000 credits!." << endl; cout << "You currently have " << credits << " credits." << endl; } else if (wheel1 == 2 && wheel2 == 2 && wheel3 == 2) { cout << "BAR - BAR - BAR" << endl; cout << "You won, yay." << endl; } else if (wheel1 == 3 && wheel2 == 3 && wheel3 == 3) { cout << "SEVEN - SEVEN - SEVEN" << endl; cout << "You won, yay." << endl; } else if (wheel1 == 4 && wheel2 == 4 && wheel3 == 4) { cout << "PLUM - PLUM - PLUM" << endl; cout << "You won, yay." << endl; } else if (5 == LEMON) { cout << "BAR - BAR - BAR" << endl; cout << "You won, yay." << endl; } else if (6 == CHERRY) { cout << "BAR - BAR - BAR" << endl; cout << "You won, yay." << endl; } else { cout << "LOSER?"; } }