Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

just need to random generate dice to roll for point. IF the first roll is a seve

ID: 3622694 • Letter: J

Question

just need to random generate dice to roll for point. IF the first roll is a seven the player wins immediately. The player continues to roll until they match the point (they win) or they roll seven or two (then they lose).
Here is what I have so far...

#include "stdafx.h"
#include <iostream>
#include <cmath>
#include <cstdlib>

int _tmain(int argc, _TCHAR* argv[])
{
int die;
int dice;
int point;

die = 1 + rand() % 6;

if ((die == 2) || (die == 3));
{
cout << "You Lose";
}
else if (dice == 7)
{
cout << "Yow win!";
}

else
{
point = dice;
do
{
if (dice == 7)
cout << "You win.";
break;
}
while (point != dice);


return 0;
}
}

Explanation / Answer

Based on the information provided, I have concluded that:

Upon the first roll, there are 3 cases to consider.

1) The die is 7, the player automatically wins.
2) The die is 2 or 3, the player automatically loses.
3) The outcome is undetermined so player continues to roll.

The first two cases are trivial. With the third case, the player keeps rolling until a winning or losing condition is met.

The winning condition is that the roll matches the point of the first roll, or is a 7.  The losing condition is if the roll is either a 2 or 3.

Based on these specifications, I have reimplemented your code.

Please go to: http://codepad.org/bfo1gkhm to see the code and a live demonstration.

Hope this helps.