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
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.
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.