# Double skull(6's) dice game. Need help T-T

• 06-10-2011
DontQueef
Double skull(6's) dice game. Need help T-T
hey guys, the program im going to post up is my homework assignment that was due last week. I have tried so many times to work this thing out, even went in for tutoring but still cant get the program to run; so ive decided to get some real help. Here are the specific details:

-MIN_BET MAX_BET and START_AMOUNT are #defined as 5, 50, and 200 respectively.
**if the call to the input function doesnt return 0, do the following:
-call a function to play double skull
-call a function to add or subtract the users money depending on the results.
-call a function to print the results of the betting.
repeat to**

-in the input function prompt for a bet(display what the users money is in prompt. if bet<MIN_BET or MAX_BET or >usersMoney and not 0 nor usersMoney<MIN_BET, print an error message and read bet again. loop until bet is 0 or between MIN_BET and MAX_BET.
-in the same function, prompt if the user wants to bet for the computer to get double 6's within 25 rolls or not. return the bet in a return statement or 0 if the usersMoney<MINBET.
- in the function to play the game. get 2 random numbers using random function in a loop until its executed 25 times. if the computer rolled double 6's. print a message stating that it rolled double 6's and display how many rolls were made, then return true. if it didnt within 25 rolls, print a message and return false.
- in the function to add or subtract users money, determine to add or subtract the money base on the bet.
- in the function that prints the results, print if the user won the bet or not. how much he/she won or lost, and how much money is left.
-use while loop, do-while loop, for loop, if statements.

*** with that said. what i have finished within the past week will be posted below. I dont want a straight up answer for my program, that would be cheating. i just hope you guys can give me some tips as to where to fix my functions and what to fix them to; an explanation would be nice too. this is a beginning c class, and the programs are driving me nuts. Thanks in advance for any tips, i greatly appreciate it.

Code:

```#include <stdio.h> #include <stdlib.h> #include <time.h> #define MIN_BET 5 #define MAX_BET 50 #define START_AMOUNT 200 bool getInput(int *pinBet, int *puserBet); int randDice(int *pdice1, int *pdice2,int *pcomputerWon,int *pcomputerLost); void calcMoney(int *puserMoney, int *pinBet); void printOutput(int dice1, int dice2, int inBet, int userMoney); int main(void) {         int inBet(0);         int userBet(0);         double userMoney(0);         int pdice1, pdice2, pcomputerWon, pcomputerLost,                 puserMoney, pinBet, betRoll, dice1, dice2;                 while(getInput(&inBet, &userBet)){                 randDice(&pdice1, &pdice2, &pcomputerWon, &pcomputerLost);                 calcMoney(&puserMoney, &pinBet);                 printOutput(dice1, dice2, inBet, userMoney);                                                                         }         system("pause");         return 0; } bool getInput(int *pinBet, int *pbetRoll) { double userMoney; if(*pinBet!=0)         return false; else{         return true;               } if(userMoney!=0)         return false; else{         return true;                                 }         printf("Enter a bet between 5 and 50, inclusive(0 to quit): ");         scanf("%d", &pinBet);         while(*pinBet<MIN_BET||*pinBet>MAX_BET||*pinBet>userMoney){                 printf("Bet is invalid\n");                 printf("Enter a bet between 5 and 50, inclusive(0 to quit): "),                 scanf("%d", &pinBet);                                 }         printf("Are you betting that the computer will roll 2 6's within 25 rolls(0 for no): ");         scanf("%d", &pbetRoll);         system ("pause");                                                                                                 } int randDice(int *pdice1, int *pdice2,int *pcomputerWon,int *pcomputerLost) {         int rollNum;         for (*pdice1=1;*pdice1<=25;++*pdice1){                 *pdice1=(rand()%6)+1;                                                                                 }         for (*pdice2=1;*pdice1<=25;++*pdice2){                 *pdice2=(rand()%6)+1;                                                                                 }         for(rollNum=1; rollNum<=25||(*pdice1==6&&*pdice2==6);++rollNum){         printf("Roll #%d, rolled %d and %d", rollNum, pdice1, pdice2);                                                                                                           }         if(*pdice1==6&&*pdice2==6){         printf("The computer rolled double skull in %d rolls", rollNum);         return *pcomputerWon;         }                 else{                 printf("The computer did NOT rolled double skull in 25 rolls");                 return *pcomputerLost;                         } } void calcMoney(int *puserMoney, int *pinBet) {         int betRoll;         int dice1;         int dice2;         if(betRoll!=0&&(dice1!=6&&dice2!=6))         *puserMoney=*puserMoney+*pinBet;                 else{                         *puserMoney=*puserMoney-*pinBet;                         } } void printOutput(int dice1, int dice2, int inBet, int userMoney) {         if(dice1==6&&dice2==6) printf("you won %d", inBet);     else{     printf("you lost %d", inBet);     } printf("your total money is now %d", userMoney); }```
• 06-10-2011
rags_to_riches
Compilations results, seeing as you couldn't be bothered to provide them:
Code:

```gcc -ggdb3 -Wall -pedantic -o queef queef.c queef.c:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getInput’ queef.c: In function ‘main’: queef.c:15: error: expected declaration specifiers or ‘...’ before numeric constant queef.c:16: error: expected declaration specifiers or ‘...’ before numeric constant queef.c:17: error: expected declaration specifiers or ‘...’ before numeric constant queef.c:21: warning: implicit declaration of function ‘getInput’ queef.c:24: warning: passing argument 3 of ‘printOutput’ makes integer from pointer without a cast queef.c:24: warning: passing argument 4 of ‘printOutput’ makes integer from pointer without a cast queef.c:19: warning: unused variable ‘betRoll’ queef.c: At top level: queef.c:30: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getInput’ queef.c: In function ‘randDice’: queef.c:67: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘int *’ queef.c:67: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int *’```
Code:

`queef.c:8: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘getInput’`
bool is not a standard C datatype; you would need to #include <stdbool.h>

Code:

```queef.c:15: error: expected declaration specifiers or ‘...’ before numeric constant queef.c:16: error: expected declaration specifiers or ‘...’ before numeric constant queef.c:17: error: expected declaration specifiers or ‘...’ before numeric constant```
Code:

```int inBet(0); int userBet(0); double userMoney(0);```
You can initialize variables that way in C++, not C. Use = 0.

Code:

`queef.c:20: warning: unused variable ‘betRoll’`
Self-explanatory

Code:

```queef.c:45: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int **’ queef.c:49: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int **’ queef.c:52: warning: format ‘%d’ expects type ‘int *’, but argument 2 has type ‘int **’```
pinBet and pbetRoll are already pointers, so you do not need to use the & in your scanf calls.

Code:

```queef.c: In function ‘randDice’: queef.c:68: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘int *’ queef.c:68: warning: format ‘%d’ expects type ‘int’, but argument 4 has type ‘int *’```
The opposite of the above. pdice1 and pdice2 are pointers, so you need to dereference them like you did elsewhere in the function before printf can use them properly.

Code:

```void calcMoney(int *puserMoney, int *pinBet) {     int betRoll;     int dice1;     int dice2;     if(betRoll!=0&&(dice1!=6&&dice2!=6))```
You did not initialize betRoll, dice1 or dice2 here, so who knows what they contain.
• 06-10-2011
DontQueef
Wow. Thanks alot for the really detailed answers, they're really helpful. =] Sorry i didnt put the scan errors up; its my first time on the forum. =DDDDD thanks again!