### Let's Make A Slot Machine

The question at the end of chapter was:
 Make a "slot machine" game that randomly displays the results of a slot machine to a player—have 3 (or more) possible values for each wheel of the slot machine. Don't worry about displaying the text "spinning" by. Just choose the results and display them and print out the winnings (choose your own winning combinations).

I did this:

 ``12345678910111213141516171819202122232425262728293031323334353637`` `````` #include #include #include using namespace std; int randRange(int high, int low); int main() { srand(time(NULL)); int random_num = randRange(10, 1); // first_ random number int random_num1 = randRange(10, 1); // second random number cout << "Please Enter to run the slot machine" << endl; cin.get(); if(random_num == random_num1) { cout << "The Numbers are " << random_num << " and " << random_num1 << ", you win" << endl; } else { cout << "The Numbers are " << random_num << " and " << random_num1 << ", you loose" << endl; } } int randRange(int high, int low) { return rand() % (high - low) + low; } ``````

Is it good enough for a slot machine?

Please Share Your methods also , How will you make Slot Machine?
Last edited on
I guess this topic must be in the lounge since this is not a programming help or issue. It's likely that you'll find positive responses there.
Can you move it there ?
Click EDIT option of this topic and change the section from beginner to Lounge.
So, there are only two slots?
When I came to that exercise I code it like that:

 ``12345678910111213141516171819202122232425262728293031323334353637383940`` ``````#include #include #include using namespace std; int sayi(int alt, int ust) { return rand()%(ust-alt)+alt; } int main() { int x,y,z; srand (time(NULL)); while(1) { x=sayi(1,4); y=sayi(1,4); z=sayi(1,4); cout<<"|---|---|---|\n"; cout<<"| "<

Note: Press ENTER to run.

Kaybettiniz = you lose
Kazandınız = You won

EDIT: Organized code
Last edited on
Isn't a slot machine one where you have fruit or whatever and you have to line up 3 of them to win?
I know what a slot machine is. How will you code what you just said?
If was doing it with graphics, I definitely use a game engine. If I was doing it in the console, I'd do it with <string> using 3 string arrays holding each fruit.
 ``1234`` ``````string slot1[10], slot2[10], slot3[10]; //Then fill the slots //Then generate random mixes of them. //Then check if 3 are lined up and give the appropriate prize (i.e. the same fruit was chosen on all 3). ``````
Last edited on
Nice!
Topic archived. No new replies allowed.