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:
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. :)
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:
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;
}
}