# Stuck on a game of craps in C

• 02-08-2012
Rob31645
Stuck on a game of craps in C
This is homework, i have the code mostly complete but am receiving a compile error that I can not figure out. any help would be appreciated. the error at compile is E2379 line 39
Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main ()
{
int i,d1,d2,sumd,sumd2;
double winf = 0, lossf = 0, winp = 0, lossp = 0;
printf("This program will simulate the game of craps for 100 times.\n");

for (i=0; i<100; i++)
{
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;

if (sumd==7 || sumd==11)
{
winf++;
}
if (sumd==2 || sumd==3 || sumd==12) {
lossf++;
}
if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
while (1)
{
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd2 = d1 + d2;

if (sumd2>=sumd)
{
printf("Win by points.\n");
winp++;
break;
}
else ((d1==7) || (d2==7))
{
printf("You rolled a 7, you lose.\n");
lossp++;
break;
}
}
}
}

printf("First roll wins: %lf\n", winf);
printf("First roll losses: %lf\n", lossf);
printf("Points wins: %lf\n", winp);
printf("Points losses: %lf\n", lossp);

return 0;
}

• 02-08-2012
I'd say that if you have written code that clear with indentation that good, yet you cannot pick up the simple error on line 38, then you must have been staring at the code too long. :P

If you still cannot see it then have a quick read through this If Statements in C - Cprogramming.com and you should kick yourself.
• 02-08-2012
Rob31645
Thanks, I am kicking myself right now
• 02-08-2012
RockyMarrone
Quote:

Originally Posted by Rob31645
This is homework, i have the code mostly complete but am receiving a compile error that I can not figure out. any help would be appreciated. the error at compile is E2379 line 39
Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main ()
{
int i,d1,d2,sumd,sumd2;
double winf = 0, lossf = 0, winp = 0, lossp = 0;
printf("This program will simulate the game of craps for 100 times.\n");

for (i=0; i<100; i++)
{
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd = d1 + d2;

if (sumd==7 || sumd==11)
{
winf++;
}
if (sumd==2 || sumd==3 || sumd==12) {
lossf++;
}
if (sumd==4 || sumd==5 || sumd==6 || sumd==8 || sumd==9 || sumd==10) {
while (1)
{
d1 = rand()%6+1;
d2 = rand()%6+1;
sumd2 = d1 + d2;

if (sumd2>=sumd)
{
printf("Win by points.\n");
winp++;
break;
}
else ((d1==7) || (d2==7))
{
printf("You rolled a 7, you lose.\n");
lossp++;
break;
}
}
}
}

printf("First roll wins: %lf\n", winf);
printf("First roll losses: %lf\n", lossf);
printf("Points wins: %lf\n", winp);
printf("Points losses: %lf\n", lossp);

return 0;
}

Statement else ((d1==7) || (d2==7)) should be else if ((d1==7) || (d2==7)).