Stuck on a game of craps in C

This is a discussion on Stuck on a game of craps in C within the C Programming forums, part of the General Programming Boards category; This is homework, i have the code mostly complete but am receiving a compile error that I can not figure ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Location
    Hawthorne, California, United States
    Posts
    9

    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;
    }

  2. #2
    Registered User
    Join Date
    Jan 2009
    Location
    Australia
    Posts
    375
    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.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Location
    Hawthorne, California, United States
    Posts
    9
    Thanks, I am kicking myself right now

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by Rob31645 View Post
    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)).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Craps - stuck
    By critical in forum C++ Programming
    Replies: 6
    Last Post: 12-13-2011, 08:47 PM
  2. Craps game in C!
    By Maria22 in forum C Programming
    Replies: 2
    Last Post: 04-09-2011, 12:13 AM
  3. Craps Game in C
    By clipsit in forum C Programming
    Replies: 3
    Last Post: 02-19-2008, 03:09 PM
  4. Craps Game
    By TWIXMIX in forum Game Programming
    Replies: 5
    Last Post: 06-12-2004, 08:47 PM
  5. help with a craps game!
    By Jessie in forum C Programming
    Replies: 10
    Last Post: 10-16-2002, 10:19 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21