Hi, so i have this program due for a CS class soon and im having trouble figuring out how to do it. At this point through in class help and the help of my peers i have a working craps program that runs 1000 times and increments a wins and losses value, but i can't figure out how to make it calculate and output the percentage of winning and losing after it runs. Here's the code i have, any advice is appreciated.
void main ()
{
enum Status {CONTINUE, WON, LOST};
int Sum, MyPoint;
int a = 0;
wins == 0;
losses ==0;
Status GameStatus;
srand(time(0));
//Roll the dice
for(a = 0; a <= 1000; a++)
{
Sum = rolldice();
cout << "You rolled " << Sum << "." << endl;
switch (Sum)
{
case 7:
case 11:
GameStatus = WON;
break;
case 2:
case 3:
case 12:
GameStatus = LOST;
break;
default:
GameStatus = CONTINUE;
MyPoint = Sum;
cout << "Point is " << MyPoint << '.' << endl;
break;
}
while (GameStatus == CONTINUE)
{
Sum = rolldice();
cout << "The roll is " << Sum << '.' << endl;
if (Sum == MyPoint)
GameStatus = WON;
else
if (Sum == 7)
GameStatus = LOST;
That's basic math right there. You just declare 2 variables. 1 For lossPercentage and the other for winPercentage; then you just do winPercentage = (wins / 1000) and lossPercentage = (losses / 1000). Then print out the values.
Because you actually did your homework and you only need help with basic math, I decided to go ahead and do it for you since I was bored anyway. I made it from scratch and redesigned it because yours was a little bit sloppy. Don't take it personally though, I am very OCD about my code and you're a beginner anyway.
Make sure you completely understand everything in the code if you're planning on turning it in as a homework assignment. I added a couple things that weren't there before including static_cast and references. Let me know if you have any questions but I don't check this site too often so I may not reply.