Slot Machine

hello there, I was solving a question of my c++ book. Which states "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)"

Here is the code I wrote:
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;

int main()
{
srand(time(NULL));
int credits = 10, money =0;

while(1)
{
int x=rand()%3+1, y=rand()%3+1, z=rand()%3+1;
if(x==1 && x==y==z)
{
cout << "you won 3 extra credits and 300$\n";
credits+=3;
money+=300;
credits--;
if(credits ==0)
{
cout << "you have zero credits\n game over\n";
break;
}
}
else if(x==2 && x==y==z)
{
cout << "you won 5 extra credits and 500$\n";
credits+=5;
money+=500;
credits--;
if(credits ==0)
{
cout << "you have zero credits\n game over\n";
break;
}
}
else if(x==3 && x==y==z)
{
cout << "you won 7 extra credits and 700$\n";
credits+=7;
money+=700;
credits--;
if(credits ==0)
{
cout << "you have zero credits\n game over\n";
break;
}
}
else
{
cout << "you lose\n";
money = money- 50;
credits = credits -5;
if(credits <=0)
{
cout << "you have zero credits\n game over\n";
break;
}
}
}
cout << "credits = " <<credits <<" money = "<< money << "$";
}
This code works. Can you please tell me, Is this what we were suppose to do?
1) There's no way any of us could know if that's what they meant, especially without knowing the book it's from. Is this for a class? If so, email your teacher/professor

2) For future reference in posting code here, wrap the code in code tags. i.e.
["code"][/code]
(without the quotations)

3) You posted this in the wrong sub. You're looking for www.cplusplus.com/forum/beginner
Last edited on
x==y==z is incorrect. It works like that:

1
2
3
4
5
6
7
bool triple_equals(int x, int y, int z)
{
    if (x == y)
        return z == 1;
    else 
        return z == 0;
}
Topic archived. No new replies allowed.