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
#include <cstdlib>
#include <iostream>
usingnamespace 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---------------------------------------------------------------
elseif(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;
}
elseif (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;
}
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.
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?
#include <cstdlib>
#include <iostream>
usingnamespace 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---------------------------------------------------------------
elseif(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;
}
elseif (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;
}
elseif(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;
}