Craps is a dice game in which the players make wagers on the outcome of the roll
ID: 3028338 • Letter: C
Question
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^2. To start a round, the shooter makes a "come-out" roll. A come-out roll of 2, 3 or is called "craps" and is an immediate loss. come-out roll of 7 or is a "natural", and is an immediate win. The other possible rolls are called the "point" numbers: 4, 5, 6, 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 a seven on subsequent rolls in order to win. Assignment: You will complete this game that you started in the last homework. Give the user 5 chips initially. Subtract 1 for a loss and add one for a win. Stop when the user is out of chips or has 10 chips. output the number of chips at the end of each game. Your program must do the following: Use a while loop for when 0Explanation / Answer
#include <iostream>
#include<stdlib.h>
#include <time.h>
using namespace std;
int chips = 5;
int num1, num2, total, t;
int fun()
{
srand(time(NULL));
num1 = rand() % 5 + 1;
num2 = rand() % 5 + 1;
cout << " You rolled:" << num1<<"and"<<num2;
t = num1 + num2;
//cout << " The number is:" << t;
return t;
}
int main()
{
while (chips>0 && chips<11)
{
total = fun();
if (total == 2||total==3||total==12)
{
cout << " You loss";
chips--;
}
else if (total == 7 || total == 11)
{
cout << " You win";
chips++;
}
else if (total == 4 || total == 5 || total == 6 || total == 7 || total == 8 || total == 10)
{
cout << " You will roll again..";
fun();
}
cout << " Chips :" << chips;
}
system("pause");
return 0;
}
Sample output:
You rolled:3and 4
You win
Chips :6
You rolled:3and 4
You win
Chips :7
You rolled:3and 4
You win
Chips :8
You rolled:3and 4
You win
Chips :9
You rolled:3and 4
You win
Chips :10
You rolled:3and 4
You win