Craps program help

Ok so here is the code i have, it builds fine but when i run it, it only goes through the code once. Is there something wrong with my loop? I need to the program to run 1000 times and then calculate the percent chance of winning. Also any tips of how to get the percent chance of winning is appreciate since im also lost on that. I have a professor who explains nothing. fml


#include <iostream>
#include <cstdlib>
#include <ctime>
#include <iomanip>

using namespace std;



int rolldice ();

void main ()
{
enum Status {CONTINUE, WON, LOST};
int Sum, MyPoint;
int a = 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;

}

if (GameStatus == WON)
cout << "You Win the game." << endl;

else cout << "You Lose the game." << endl;

}
}

int rolldice()
{
int Die1, Die2;
int Total;
Die1 = (rand() % 6) +1;
Die2 = (rand() % 6) +1;
Total = Die1 + Die2;
return Total;
}

By adding a semi-colon after the for loop declaration for(a = 0; a <= 1000; a++); you've defined an empty loop, followed by a block of code ({ }) containing your intended loop code.

Cheers,
Jim
Ah you were right! thank you, now can anyone tell me where i would need to add what to calculate the percentage of wins, i've tried on my own and just get syntax errors and such. I have python knowledge but this c++ is killing my, my professor doesn't explain anything, im drowning here.
You need to know how many winning throws were made out of the 1000 turns and do the appropriate math.

Counting the winning throws would be a matter of incrementing the count every time you win a game.
I tried to do that but got errors. I declared wins and losses variables after using namespace std;

then i tried ti increment them here


if (GameStatus == WON)
cout << "You Win the game." << endl;
wins = wins++;
else cout << "You Lose the game." << endl;
losses = losses++;

do i maybe need to use cin? and then i just do the math when i get those values, outside of which brackets?
@Alexpil

That code needs to look like this. Without the braces, wins++ and losses++ would be accessed no matter if it was a win or not.

1
2
3
4
5
6
7
8
9
10
if (GameStatus == WON)
{
cout << "You Win the game." << endl;
 wins++;  
}
else 
{
cout << "You Lose the game." << endl;
losses++;
}
Last edited on
Topic archived. No new replies allowed.