Need some help with homework, any help would be appreciated.
Here's the assignment:
BACKGROUND: Craps is a dice game in which the players make wagers on the outcome of the roll, or series of rolls, of a pair of dice. To start a round, the shooter makes a "come out" roll. A come-out roll of 2,3, or 12 is called "craps" and is an immediate loss. A come-out roll of a 7 or 11 is a "natural", and is an immediate win. The other possible rolls are call "point" numbers: 4,5,8,8,9, and 10. if the shooter rolls one of these numbers on the come out roll, this establishes the "point", and the point number must be rolled again before the seven on subsequent rolls in order to win. In other words, you keep rolling until a 7 or the point is rolled. Rolling the point will be a win and rolling a 7 will be considered a loss.
Part1: Simulate the first roll of 2 dice, and depending on the two-die total, output whether the players wins, loses, or continues with the roll being the point value.
-Simulate dice roll using rand() function twice
-Initalize the random number generator using time(0) function call
-Use a switch statement depending on the 2-dice roll total
-Use a bool data type to store whether the user will roll again or not
Part2: Give the user 5 chips initially. Subtract 1 for a loss and add 1 for a win. Stop when the user is out of chips or has 10 chips. Output the number of chips at the end of the each game. Program should do the following:
-Use a while loop for when 0<chips<11
-Use a while loop when attempting the point value.
-Stop when chips are 0 or greater than 10
-Use switch statements
Here is what i have so far:
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
|
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;
int rollDice();
int die1;
int die2;
int rollSum;
int sum;
int rollPoint;
string status;
int main()
{
sum = rollDice();
switch (sum)
{
case 2:
case 3:
case 12:
status = "lose";
break;
case 7:
case 11:
status = "win";
break;
default:
status = "point";
rollPoint = sum;
break;
}
cout << "You rolled " << die1 << " + " << die2 << " = " << sum << endl;
while (status == "point")
{
cout << "point is " << rollPoint << endl;
sum = rollDice();
cout << "You rolled " << die1 << " + " << die2 << " = " << sum << endl;
if (sum == rollPoint)
status = "win";
else if (sum == 7)
status = "lose";
else
status = "point";
}
if (status == "win")
cout << "You win!" << endl;
if (status == "lose")
cout << "You lose!" << endl;
return 0;
}
int rollDice()
{
die1 = (rand() + time(0)) % 6 + 1;
die2 = (rand() + time(0)) % 6 + 1;
rollSum = (die1 + die2);
return rollSum;
}
|