So the assignment requires us to make a game of Craps and also put three constants in the program. The game works I'm just trying to figure out how I would get a constant into the code. I have set three constants. SnakeEyes = 2, Boxcars = 12, and BigRed =7. Should I be going at this another way?
#include <iostream>
#include <ctime>
#include <time.h>
#include <cstdlib>
usingnamespace std;
int main()
{
int die1; //The first die.
int die2; //The second die.
int rollingDice; //When the player throws dice
int rollingDice2 = 0; //When the player throws the dice if the first throw didn't give a winning or losing outcome.
constint SnakeEyes = 2; //If the player throws two ones.
constint BoxCars = 12; //If the player throws two sixes.
constint BigRed = 7; //If the player throws a three and four
srand(22);
die1 = rand() % 6 + 1; //Simulates a six sided die
die2 = rand() % 6 + 1;
rollingDice = die1 + die2; //Adds the dice together.
cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice << endl << endl; //Shows what the player rolled on first try.
if (rollingDice == 7 || rollingDice == 11) //Player wins if they get a 7 or 11.
{
cout << "You won!" << endl;
cin.get();
return 0;
}
if (rollingDice == 2 || rollingDice == 3 || rollingDice == 12) //Player loses if they get a 2, 3, or 12 on first try.
{
cout << "Craps! You lost!" << endl;
cin.get();
return 0;
}
else
{
cout << "The Point is " << rollingDice << endl << endl; //If the player rolled a 4, 5, 6, 8, 9, or 10 on first try the game continues.
}
if (rollingDice == BoxCars)
{
cout << "Boxcars!" << endl;
}
while (rollingDice2 != rollingDice && rollingDice2 != 7) //Attempts will be made until the player either rolls the same number or a 7.
{
die1 = rand() % 6 + 1;
die2 = rand() % 6 + 1;
rollingDice2 = die1 + die2;
cout << "Player rolled: " << die1 << " + " << die2 << " = " << rollingDice2 << endl << endl;
if (rollingDice2 == rollingDice)
{
cout << "You rolled your point! You won!" << endl; // The player matched their number they won.
}
if (rollingDice2 == 7)
{
cout << "You seven'd out and lost!" << endl; // The player got a total of seven they lost.
}
}
cin.get();
return 0;
}