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



LinkBack URL
About LinkBacks


