I should use functions to make it work.
Here is simplified craps rules:
Player rolls two dice.
When the sum is 7 or 11 on first throw, player wins.
When the sum is 2, 3, or 12 on first throw, player lose.
When the sum is 4,5,6,8,9, or 10 on first throw, that sum becomes the player's "point".
Now, to win the player must continue rolling the dice until he makes "point"; however if the player roll a 7 the player lose.
I'm having trouble with the 3th rule ( When the sum is 4,5,6,8,9, or 10 on first throw, that sum becomes the player's "point".
Now, to win the player must continue rolling the dice until he makes "point"; however should he roll a 7 the player lose. )
#include <iostream> #include <cstdlib> #include <ctime> using namespace std; int perdu(int &jet10, int &m1s3) // function called when player lose { return jet10 -= m1s3; } int gagne(int &jet10, int &m1s3) // function called when player win { return jet10 += m1s3*2; } int lance() // function roll. { int de1,de2,somme; de1 = rand()%6+1; de2 = rand()%6+1; somme = de1 + de2; return somme; } void jouerCraps() // function playcraps { retry: char retry; // asked for retry at the end of program int jetons = 10; // cash int parie=1; // bet int tmp; int tmp1; cout<<"-------------------------------------------------------"<<endl; cout<<" XxCRAPSxX "<<endl; cout<<"-------------------------------------------------------"<<endl; debut: while(parie !=0 && parie < jetons) { head: cout << "choose amount to bet "<< 1 << " between " << jetons << " (0 for quit) : "; cin >> parie; if(parie == 0) { break; } if(parie > jetons) { cout << "Your bet can't be higher than your cash"<<endl; goto head; } tmp = lance(); if((tmp == 7) || (tmp ==11)) // checking 1st rule { cout << "Roll :" << tmp <<endl; cout << "You win"<<endl; gagne(jetons,parie); goto debut; } else if((tmp == 2) || (tmp == 3) || (tmp == 12)) // checking 2nd rule { cout << "Roll :" << tmp <<endl; cout << "You lose"<<endl; perdu(jetons,parie); goto debut; } else cout << "Roll :"<< tmp <<endl; //checking 3th rule while(tmp1!= tmp) { cout << "Roll :" << lance() <<endl; tmp1 = lance(); if(tmp1 == 7) { cout << "Roll :" << tmp1 <<endl; cout << "You lose"<<endl; perdu(jetons,parie); goto debut; } } cout << "Roll :" << tmp1 <<endl; cout << "You win"<<endl; gagne(jetons,parie); goto debut; } tour: cout << "Retry again? : Y/N" <<endl; cin >> retry; if(retry == 'Y' or 'y') { goto retry; } else if(retry == 'N' or 'n') { cout <<"Ciao!!"<<endl; } else { cout<<"Write only Y for yes or N for no"<<endl; goto tour; } } int main() { srand(time(NULL)); jouerCraps(); }
Comment