slot machine

Im trying to make a simple slot machine but i dont undersand why the output wont work. It is only sappose to output one line consisting of the the outputs. Here is my code:

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void slot_output();
void combos(int x);


int main(){

slot_output();
system("pause");
return 0;
}

void slot_output(){

srand((unsigned)time(0));
int random_integer;

for(int index=0; index<3; index++){
random_integer = (rand()%5)+1;
combos(random_integer);
}

}

void combos(int x){
switch (x){
case 1: cout<< " Cherry ";
case 2: cout<< " Bell ";
case 3: cout<< " Plum ";
case 4: cout<< " orange ";
case 5: cout<< " Bar ";
//default: cout <<"ERROR";
}
}
I'm going to guess that you didn't intend to leave out the breaks after each of the cases in your switch. What you have now will result in a few fall-throughs. :)

-Albatross
Last edited on
ok i got that fixed and added a few thing but there is one more problem now. Everythign works except the program doesnt keep track of the total money properly. The outout should show the total money you have left but the value it returns for this is wrong. Here is my code im pretty sure the problem occurs with the TrackMoney function and when it is called:

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>

using namespace std;

void slot_output(); // initializing functions
void combos(int x);
int CashMoney1 (int x);
void SpitMoney (int x, int y,int z);
int TrackMoney (int x, int y,int z,int money);

int main(){

slot_output(); // calling slot machine program

system("pause");
return 0;
}

void slot_output(){ // main slot machine program
int money = 100; //initial starting money
while (money =! 0){
string play;
cout << "Enter 00 to play!" << endl;
cin >> play;
if(play == "00"){
srand((unsigned)time(0));
int random_integer,i,j,k;
for(int index=0; index<3; index++){
random_integer = (rand()%5)+1; // calculating random number
combos(random_integer);
if (index == 0){
j = CashMoney1 (random_integer);
}
if (index == 1)
{
k = CashMoney1 (random_integer);
}
if (index == 2)
{
i = CashMoney1 (random_integer);
}
}
SpitMoney (j, k,i); // this tell the user how much they have won in a text
money = TrackMoney (j,k,i,money); // this is where i think the problem is because this should show how much money you have left
cout <<" You have "<< money << " left."<<endl;

}
}
cout << "You are out of money!"<<endl;
}
int TrackMoney (int x, int y,int z,int money){
int sum = x+y+z;
int cash;
if (x == 1 && y == 1){
cash = money + 5 ;
}
else if (x==1)
{
cash = money + 2;
}
else{

switch (sum){
case 30000 : cash = money + 250;break;
case 30: cash = money +20;break;
case 10030: cash = money +20;break;
case 10300: cash = money +14;break;
case 300: cash = money +14;break;
case 3000: cash = money +10;break;
case 13000: cash = money +10;break;
case 3:cash = money +7;break;
default: cash = money - 1; break;
}
}
return cash;
}

void SpitMoney (int x, int y,int z){
int sum = x+y+z;

if (x == 1 && y == 1){
cout << "You have won $5!"<< endl;
}
else if (x==1)
{
cout << "You have won $1!" << endl;
}
else{

switch (sum){
case 30000 : cout << " Congradualtions you have won $250!" << endl;break;
case 30: cout << " You have won $30!"<< endl;break;
case 10030: cout << " You have won $30!"<< endl;break;
case 10300: cout << " You have won $14!"<< endl;break;
case 300: cout << " You have won $14!"<< endl;break;
case 3000: cout << " You have won $10!"<< endl;break;
case 13000: cout << " You have won $10!"<< endl;break;
case 3:cout << " You have won $7!"<< endl;break;
default: cout << " You have lost $2!"<< endl;break;
}
}

}


int CashMoney1 (int x){ // i used this function so i can sort the possiable output combinations
int n;
n =0;

switch (x){
case 1: n++; break;
case 2: n = 10; break;
case 3: n = 100; break ;
case 4: n = 1000; break;
case 5: n = 10000; break;
}
return n;
}

void combos(int x){

switch (x){
case 1: cout<< " Cherry "; break;
case 2: cout<< " Bell "; break;
case 3: cout<< " Plum "; break ;
case 4: cout<< " Orange "; break;
case 5: cout<< " Bar "; break;
}
}
Could you please wrap your code between [ code] [ /code] tags?
i have a simple slot machine.....
||
_||_
\ /
\ /
\/

HERE>>>>

#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;

int Random(int low, int high)
{
int rand_num = low + rand() % ((high + 1) - low );
return rand_num;
}

int main()
{

int low1(2), low2(2), low3(2);
int high1(7), high2(7), high3(7);
int cash = 1000;
int num;
int bet;

cout << "Player´s chips: $" << cash << endl;

while (true)
{

cout << "1) Play slot. 2) Exit. ";
cin >> num;


if (num == 2)
{
cout << "Exiting..." << endl;
break;
}


else if (num == 1)
{
cout << "Enter your bet: ";
cin >> bet;

if (bet > cash || bet < 0 || bet == cash || bet == 0)
{
cout << "You did not enter a valid bet." << endl;
}

else
{
srand( time(0) );

int first = Random(low1, high1);
int second = Random(low2, high2);
int third = Random(low3, high3);

string s1 = "You won!";

cout << first << " " << second << " " << third << endl;

if (first == 7 && second == 7 && third == 7)
{
cout << s1 << endl;
cash += bet * 10;
}
else if (first == second == third)
{
cout << s1 << endl;
cash += bet * 5;
}
else if (first == second || second == third || first == third)
{
cout << s1 << endl;
cash += bet * 3;
}
else
{
cout << "You lose!" << endl;
cash -= bet;
}

if (cash < 0)
{
cout << "You have no more money left!" << endl;
cout << "Exiting..." << endl;
break;
}

cout << "Player´s chips: $" << cash << endl;


}

}

else
{
cout << "You did not enter a valid number!" << endl;
}

}
}
Topic archived. No new replies allowed.