Thread: Craps Game in C

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    33

    Craps Game in C

    THe game is suppose to start with 1000 dollars and zero chips and it is starting with over 5 million chips I need help I dont know where I went wrong

    Code:
    #include <stdio.h>
    
    
    int main(){
    
    int menu_number=0, totalmoney, moneyspent, newchips, totalchips,
    rollone, rolltwo, totalroll, numchips, moneyreturned, initialbet;
    int winorlose, r, endreport, endmoney;
    srand(time(0));
    
    
    
     totalmoney=1000;
     //menu loop
     while(menu_number != 6){
    
            printf("Welcome to the casino you can:\n");
            printf("1) Buy Chips\n");
            printf("2) Sell Chips\n");
            printf("3) Play Craps\n");
            printf("5) Status Report\n");
            printf("6) Quit\n");
            printf("Please choose now:");
            scanf("%d", &menu_number);
    
     //Option 1 buy chips
             if( menu_number==1)
             {
             printf("How much would like to spend:");
              scanf("%d", &moneyspent);
    
                    while(moneyspent> totalmoney){
                          printf("You dont have that much money plz enter a new amount......\n");
                          scanf("%d", &moneyspent);
                          }
        totalmoney-= moneyspent;
        newchips= buychips(&moneyspent);
        totalchips+=newchips;
        totalmoney+= moneyspent;
    
    }
    
    //option2 sell chips
                if(menu_number==2)
                    {
       printf("How many chips will you be selling:");
       scanf("%d", &numchips);
                   while(numchips> totalchips){
                    printf("You dont have that many chips chump try again:");
                    scanf("%d", &numchips);
                    }
       moneyreturned=sellchips(numchips);
       totalmoney+=moneyreturned;
       totalchips-=numchips;
       printf("you have $%d", totalmoney);
       printf("you have %d chips", totalchips);
    
    }
    
    
    
    
    
    
    
    
       //option 3 craps
       if(menu_number==3)
       {
                   if
                   (totalchips > 0){
                            printf("How much would you like to bet:");
                            scanf("%d", &initialbet);
    
                            while(totalchips < initialbet)
                            {
                                                       printf("You bet too much!!!Please enter correct bet:");
                                                       scanf("%d", &initialbet);
                                                       }
    
                            winorlose=craps();
                            if(winorlose==1){
                            totalchips+=initialbet;
                            printf("You win you have %d chips\n", totalchips);
    
                            }
                            else if(winorlose==0){
                            totalchips-=initialbet;
                            printf("You lose you have %d chips\n", totalchips);
                            }
    
                 }
                 else if(totalchips==0){
                      printf("You have no chips go buy some\n");
                 }
            }
    
        //option 4 arub
       if(menu_number==4)
        {
                 if(totalchips > 0){
                            printf("How much would you like to bet:");
                            scanf("%d", &initialbet);
    
                            while(totalchips < initialbet)
                            {
                                                       printf("You bet too much!!!Please enter correct bet:");
                                                       scanf("%d", &initialbet);
                                                       }
    
    
                            if(winorlose==1){
                            totalchips+=initialbet;
                            printf("You win you have %d chips\n", totalchips);
    
                            }
                            else if(winorlose==0){
                            totalchips-=initialbet;
                            printf("You lose you have %d chips\n", totalchips);
                            }
    
                 }
                 else if(totalchips==0){
                      printf("You have no chips go buy some\n");
                 }
    
    
        }
        //option 5 status
        if(menu_number==5){
                           endreport=statusreport(totalmoney,totalchips);
                           printf("Go bet more money");
                           }
    
       if(totalmoney<11 && totalchips==0)
                        {
                        printf("you out of money\n");
                        menu_number=6;
                        }
    
    
    
    }
    
    endmoney= totalmoney + (totalchips*10);
    printf("Thank you for playing you have $%d\n", endmoney);
    
    system("pause");
    return 0;
    
    }
    // dice fuction
    
    int pairofdice()
    {
       int rollone, rolltwo, totalroll,r;
       printf("Please press '1' and enter to roll\n");
       scanf("%d", &r);
       rollone= 1 +rand()%6;
       rolltwo=1+rand()%6;
       totalroll= rollone +rolltwo;
       return totalroll;
    }
    //buy chips function
    
    int buychips(int *moneyspent)
    {
       int newchips, chipprice=11, remainder;
       newchips= (*moneyspent)/chipprice;
       *moneyspent= *moneyspent% chipprice;
       return newchips;
    
    }
    //sell chip function
    int sellchips(int numchips){
       int moneyreturn;
       moneyreturn =numchips * 10;
       return moneyreturn;
    
    }
    //Craps Function
    int craps(){
       int r1, r2, r, k;
       r1=pairofdice();
       printf("You Rolled a %d\n", r1);
       if ( r1==7 || r1==11)
          return 1;
       if ( r1==2 || r1==3 || r1==12)
          return 0;
          else{
               r2=pairofdice();
               printf("You Rolled a %d\n", r2);
               while ( r2 != r1 || r2 != 7 ){
                     if (r2==r1)
                     return 1;
                     if (r2==7)
                        return 0;
                        else {
                        r2=pairofdice();
                        printf("You Rolled a %d\n", r2);}
    }}}
    
    
    
    //status report
    int statusreport(int totalmoney, int totalchips){
       printf("You have $%d and %d chips\n",totalmoney,totalchips);
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    And you set the starting number of chips where, exactly?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    I need help I dont know where I went wrong
    And you suppose someone else will know it?
    You can start with description of your problem:
    What you expect to receive
    What you receive
    What is the difference you cannot explain between 2 outputs
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    33
    thanks... i figured it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please comment on my c++ game
    By MegaManZZ in forum Game Programming
    Replies: 10
    Last Post: 01-22-2008, 11:03 AM
  2. Craps Game
    By TWIXMIX in forum Game Programming
    Replies: 5
    Last Post: 06-12-2004, 07:47 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 04:19 AM
  4. help with a craps game!
    By Jessie in forum C Programming
    Replies: 10
    Last Post: 10-16-2002, 09:19 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-24-2002, 11:00 PM