Please help

SOLVED THIS PROBLEM NEED HELP AN ANOTHER ONE BELLOW!!!

for some reason every time i play craps it rolls the dice and no matter wat number i get i end up winning? and im only supposed to win if i get a 7 or 12

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
#include <cstdlib>
#include <iostream>

using namespace std;

void clearScreen();

int findDice (int dice);

int main(int argc, char** argv) {
    string game;
    int chips=100;
    cout<<"Welcome to the online casino"<<endl;
    cout<<"What game would you like to play We have "
        <<"slots and craps"<<endl;
    
    cin>>game;
    clearScreen();
    
    srand (time(0));
    
    
  
    if (game=="slots"){//slots start ------------------------------------------
        
    }//slots end---------------------------------------------------------------
    
    
    else if(game=="craps"){//craps---------------------------------------------
        string again;
        cout<<"Welcome to Craps"<<endl;
        cout<<"each game will cost you 5 chips"<<endl;
        cout<<"You have "<< chips <<" chips"<<endl;
        cout<<"Type start when you are ready to play"<<endl;
        string start;
        cin>>start;
        
        if (start=="start"){
            do {
                clearScreen();
                chips-=5;
                cout<<"You have "<< chips <<" chips"<<endl;
                int dice=0;
                dice = findDice(dice);
                cout<<dice<<endl;
                if(dice=7&&11){
                    chips+=10;
                    cout<<"You WIN 10 chips!"<<endl;
                    cout<<"Your now have " <<chips<<" chips left"<<endl;
                }
                else if (dice=2||3||12){
                    cout<<"Sorry you lose"<<endl;
                    cout<<"Your now have " <<chips<<" chips left"<<endl;
                }
                else{
                    cout<<"round 2"<<endl;
                }
                
                
                cout<<"would you like to play again enter yes or no"<<endl;
                cin>>again;
            }while(again=="yes");
            
        }
        
    }//craps------------------------------------------------------------------
    
    
    
    
    
    return 0;
}
void clearScreen(){
    int i;
    for(i=0;i<30;i++){
        cout<<endl;
    }
}

int findDice (int dice){
        int dice1 = rand()%5+1;
        int dice2 = rand()%5+1;
        dice = dice1 + dice2;
        return dice;
}
Last edited on
if(dice=7&&11)

I think you mean to check if the value is 7 or 11?
if(dice == 7 || dice == 11)

Similar thing on line 51.


Also - rand()%5+1;

rand%5 returns a random value in a range of 0 through 4.
Adding 1 means the value will be in the range of 0 through 5.
You're not going to ever get a 6 with this.
thanks for the help @wildblue
Last edited on
ok so my next problem is that on my do/while loop i get stuck in the loop when i loss or win? and i cant use break; to get out of the loop :(
how would be the best way out of the loop?

LINES 67-87


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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#include <cstdlib>
#include <iostream>

using namespace std;

void clearScreen();
std::string find(int num, string output);

int findDice (int dice);

int main(int argc, char** argv) {
    string game;
    int chips=100;
    cout<<"Welcome to the online casino"<<endl;
    cout<<"What game would you like to play We have "
        <<"slots and craps"<<endl;
    
    cin>>game;
    clearScreen();
    
    srand (time(0));
    
    
  
    if (game=="slots"){//slots start ------------------------------------------
        int spot1 = rand()%13;
        string test;
        find(spot1,test);
        
        
        cout<<spot1<<"    "<<endl;
        
        
    }//slots end---------------------------------------------------------------
    
    
    else if(game=="craps"){//craps---------------------------------------------
        string again;
        cout<<"Welcome to Craps"<<endl;
        cout<<"each game will cost you 5 chips"<<endl;
        cout<<"You have "<< chips <<" chips"<<endl;
        cout<<"Type start when you are ready to play"<<endl;
        string start;
        cin>>start;
        
        if (start=="start"){
            do {
                clearScreen();
                chips-=5;
                cout<<"You have "<< chips <<" chips"<<endl;
                int dice=0;
                dice = findDice(dice);
                cout<<dice<<endl;
                if(dice==7||dice==11){
                    chips+=10;
                    cout<<"You WIN 10 chips!"<<endl;
                    cout<<"Your now have " <<chips<<" chips left"<<endl;
                }
                else if (dice==2||dice==3||dice==12){
                    cout<<"Sorry you lose"<<endl;
                    cout<<"Your now have " <<chips<<" chips left"<<endl;
                }
                else{
                    cout<<"round 2"<<endl;
                    int dice2;
                    string a;
                    do{
                        dice2 = findDice(dice2);
                        cout<<dice2<<endl;
                        if(dice2==dice){
                           chips+=10;
                    cout<<"You WIN 10 chips!"<<endl;
                    cout<<"Your now have " <<chips<<" chips left"<<endl;
                    
                        }
                        else if(dice2==7){
                    cout<<"Sorry you lose"<<endl;
                    cout<<"Your now have " <<chips<<" chips left"<<endl;
                    
                        }
                        else{
                            cout<<"Please enter roll when you ant to "
                                <<"re-roll"<<endl;
                            cout<<"roll a "<<dice<<" to win! "<<endl;
                            cin>>a;
                        }
                    }while(a=="roll"); 
                }
                
                
                cout<<"would you like to play again enter yes or no"<<endl;
                cin>>again;
            }while(again=="yes");
            
        }
        
    }//craps------------------------------------------------------------------
    
    
    
    
    
    return 0;
}
void clearScreen(){
    int i;
    for(i=0;i<30;i++){
        cout<<endl;
    }
}
string find(int num,string output){

	

	if(num=0){
            output="x";
           
        }
        else {
            output="tryagain";
            
        }
        
        

	return output;
}


int findDice (int dice){
        int dice1 = rand()%6+1;
        int dice2 = rand()%6+1;
        dice = dice1 + dice2;
        return dice;
}
Last edited on
Topic archived. No new replies allowed.