I'm developing a small craps game in C++, and my C++ skills are a bit rusty. I really need someone to review my code to ensure that I have correctly implemented the game according to the rules.
Game rules:
- The player or shooter rolls a pair of standard dice
- If the sum is 7 or 11 the game is won
- If the sum is 2, 3 or 12 the game is lost
- If the sum is any other value, this value is called the shooter’s point and he continues rolling until he rolls a 7 and loses or he rolls the point again in which case he wins
- If a game is won the shooter plays another game and continues playing until he loses a game, at which time the next player around the Craps table becomes the shooter
My code:
#include <iostream>
#include <ctime>
using namespace std;
bool checkWinning(int roll);
int main(int argc, const char * argv[])
{
//create player aka shooter
//create pair of dice
unsigned int dice1=0;
unsigned int dice2 = 0;
//create roll
unsigned int roll = 0;
//create game loop
while(checkWinning(roll) == true)
{
dice1 = rand() % 6 + 1;
dice2 = rand() % 6 + 1;
roll = dice1 + dice2;
cout<< dice1<<" +"<< dice2<<" = "<< roll << endl;
//cout<< checkWinning(2) <<endl;
}
return 0;
}
bool checkWinning(int roll)
{
bool winner = true;
if( roll == 2 || roll == 3 || roll == 12)
return winner= false;
else
if(roll == 7 || roll == 11 )
return winner;
else
return winner;
};