Slot Machine Program

Well this class has blown my confidence all to 773H.

I need to know why this problem won't select and print 3 elements out of 6 when randomly selected. It only prints one word.
I need to know why it won''t display a running and updated total after each bet.

The problem is to design a slot machine that displays 3 (one-armed bandit type of words), The player starts with $100 dollars, enters the amount of his bet.
Three random words are display (out of a set of 6). no matches = balance - $10; 2 matches is bal= bal + (2* bet); 3 matches pays bal= bal +(bet *2). A fluctuating total is displayed after each bet.

Does one ever get to the point where it doesn't take 16 hours of work to have not found a solution?

I'd be grateful for any help anyone can give.

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <stdbool.h>

using namespace std;

//function prototypes

//global constants

int main()
{
int drums[3];
string Cherries, Oranges, Bells, Bars, Plums, Melons;
int g = rand()% 6;
int bal = 100;
int bet = 0;
int i = 0;

cout<<"Slot Machine"<<endl;
cout<<endl<<endl;
cout<<"Rules \n";
cout<<"You have $100.00 to start. \n";
cout<<"If none of the words match you lose $10.00.\n";
cout<<"If 2 of the words match you win twice the amount of your bet.\n";
cout<<"If all 3 of the words match you win three times the amount of your bet."<<endl;
cout<<endl<<endl;

cout<<"Enter the amount you wish to bet. (control + c to quit)"<<endl;
cin>>bet;

for(i=0; i<3; i++)
{

(g = (rand() % 6)+1);
}


switch(g)
{
case(0):
cout<<"Cherries"<<endl;
break;

case(1):
cout<<"Oranges"<<endl;
break;

case(2):
cout<<"Plums"<<endl;
break;

case(3):
cout<<"Bells"<<endl;
break;

case(4):
cout<<"Melons"<<endl;
break;

case(5):
cout<<"Bars"<<endl;
break;

default:
cout<<"Error: Invalid symbol."<<endl;

}
//no matches
if(drums[0] != drums[1] && drums[1] != drums[2] && drums[0] != drums[2])
{
cout<<"You lost! No words matched. You have $ "<<endl;
bal = bal - 10;
//cout<<"Bet again? (control + c to quit)"<<endl;
}
//3 matches
if(drums[0] == drums[1] && drums[1] == drums[2])
{
cout<<"You won! 3 words matched. You have $ "<<endl;
bal = bal + (bet * 3);
cout<<"Bet again? (control + c to quit)"<<endl;
}
else
{

cout<<"You won! 2 words match. You have $ "<<endl;
bal = bal + (bet *2);
cout<<"Bet again? (control + c to quit)"<<endl;
}

cin.get();
cin.get();

return 0;
}//end main





[/code]
Sorry about the format, I put it between the code section. I'll try again.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <stdbool.h>

using namespace std;

//function prototypes

//bool randomWords(string);

//global constants

int main()
{
    int drums[3];
    string Cherries, Oranges, Bells, Bars, Plums, Melons;
    int g = rand()% 6;
    int bal = 100;
    int bet = 0;
    int i = 0;

    cout<<"Slot Machine"<<endl;
    cout<<endl<<endl;
    cout<<"Rules \n";
    cout<<"You have $100.00 to start. \n";
    cout<<"If none of the words match you lose $10.00.\n";
    cout<<"If 2 of the words match you win twice the amount of your bet.\n";
    cout<<"If all 3 of the words match you win three times the amount of your bet."<<endl;
    cout<<endl<<endl;





    cout<<"Enter the amount you wish to bet. (control + c to quit)"<<endl;
    cin>>bet;

   for(i=0; i<3; i++)
    {

       (g = (rand() % 6)+1);
    }


        switch(g)
        {
          case(0):
          cout<<"Cherries"<<endl;
          break;

          case(1):
          cout<<"Oranges"<<endl;
          break;

          case(2):
          cout<<"Plums"<<endl;
          break;

          case(3):
          cout<<"Bells"<<endl;
          break;

          case(4):
          cout<<"Melons"<<endl;
          break;

          case(5):
          cout<<"Bars"<<endl;
          break;

          default:
          cout<<"Error: Invalid symbol."<<endl;

    	}
      //no matches
        if(drums[0] != drums[1] && drums[1] != drums[2] && drums[0] != drums[2])
        {
            cout<<"You lost! No words matched. You have $  "<<endl;
                bal = bal - 10;
            //cout<<"Bet again? (control + c to quit)"<<endl;
        }
        //3 matches
        if(drums[0] == drums[1] && drums[1] == drums[2])
        {
            cout<<"You won! 3 words matched. You have $  "<<endl;
                bal = bal + (bet * 3);
            cout<<"Bet again? (control + c to quit)"<<endl;
        }
        else
         {

           cout<<"You won! 2 words match. You have $  "<<endl;
                bal = bal + (bet *2);
        }




    return 0;
//end main
}



Firstly, line 18 is useless (and shouldn't even compile, you haven't included <string>).

Every time, you are overwriting "g" in your "for" loop at line 40. Also, you are never setting the values for "drums". You will need to put your switch statement within your for loop, and then have the case for "Cherries" set drums[i] to "Cherries", etc.

Hope this helps!
Topic archived. No new replies allowed.