I bet you guys have already seen this assignment around here:
So here is the program statement
(1) One of the players goes first. That player announces the size of the bet, and rolls the dice. If the
player rolls a
• 7 or 11, it is called a natural. The player who rolled the dice wins.
• 2, 3 or 12, it is called craps. The player who rolled the dice loses.
• If the player's first roll is any other number (4, 5, 6, 8, 9, or 10) the bet is not immediately
decided. Instead, the number that the player rolled becomes the point and he continues to roll
the dice until either he rolls the point a 2nd time, in which case he wins, or he rolls a 7, in which
case he loses. For example, suppose a player's 1st roll is a 6.Then 6 becomes the point. He must
roll again. If his next roll were a 3, he would have to roll a 3rd time. The point remains 6. He
continues to roll the dice until he either gets a 6 (a win) or a 7 (a loss).
(2) When a player wins, he collects the bet, and gets to keep the dice and take another turn. Then the
play begins again with rule (1).
(3) When a player loses, his opponent collects the money that was bet and it becomes the opponent's
turn to roll the dice. The opponent starts play again with rule (1)
And when player 2 places a wager if his balance is greater than what it originally was he will wager 150 and if it is less he will wager 50. while player 1 always wagers 100.
I'm barely getting started with it. Unfortunately my dice won't roll random (they always equal 12), also, even when it rolls 12, the switch statement won't work. These are my 2 most pressing questions at the moment but as I move on I'm sure I'll have more!
Thanks for the help in advanced!
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
|
#include <iostream>
#include <cstdlib>
#include <ctime> //for time!
using namespace std;
void sim();
int main() //main function
{
int WagerNumber=1;
int player1bet=100;
int player2bet;
int player2balance=1000;
int die1 =(rand() % 6) + 1;
int die2 =(rand() % 6) + 1;
int totalroll = die1 + die2;
int totalpoint = totalroll;
srand(time(NULL)); //makes time random
cout << "Wager " << WagerNumber << " : " << "Bet is " << player1bet << "." << endl;
cout << "Player 1 is rolling the dice." << endl;
cout << "The roll is a " << totalroll << "." << endl;
//switch case block gives you many options
switch (totalroll)
{
case '7' : cout << "Natural! The player who rolled the dice wins!" << endl;
break;
case '11': cout << "Natural! The player who rolled the dice wins!" << endl;
break;
case '2' : cout << "Craps! The player who rolled the dice loses!" << endl;
break;
case '3' : cout << "Craps! The player who rolled the dice loses!" << endl;
break;
case '12': cout << "Craps! The player who rolled the dice loses!" << endl;
}
if (totalroll = 4||5||6||8||9||10)
cout << "The point is " << totalpoint << " ." << "Player 1 rolls again."<< endl;
//this if/else determines player2's bet according to his/her balance
if (player2balance>=1000)
player2bet=150;
else if (player2balance<1000)
player2bet=50;
return 0;
}
|