Ok ive tried to create a simple craps game, yet there are some errors and warnings i cant figure out.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int money=200;
void menu();
void rules();
initbet();
roll();
secbet();
char secroll(int);
void main()
{
srand((int)time(NULL));
printf("---------------------------\n");
printf("WELCOME TO THE CRAPS TABLE\n");
printf("---------------------------\n");
menu();
}
void menu()
{
int bet;
int backbet;
int point;
int gain;
char choose;
char win;
do
{
printf("Would you like to see the rules? y/n.\n\n");
fflush(stdin);
scanf("%c\n",&choose);
}
while(choose!='y' && choose!='n');
if(choose=='y')
rules();
while(1)
{
bet = initbet();
point = roll();
switch(point)
{
case 7:
case 11:
printf("Congrats! You've won %i!\n",bet);
money+=bet;
point=1;
break;
case 2:
case 3:
case 12:
printf("Sorry, you lose %i!\n\n",bet);
money-=bet;
point=1;
break;
default:
break;
}
if(money<= 0)
{
printf("Sorry you lost,but now you have no money! Goodbye.\n\n");
break;
}
if(point==1)
{
do
{
printf("Would you like to play again?y/n.\n");
fflush(stdin);
scanf("%c\n",&choose);
}
while(choose != 'y' && choose != 'n');
if(choose=='y')
continue;
else if(choose=='n')
break;
}
printf("Your point roll is %i\n\n",point);
backbet = secbet(bet);
win = secroll(point);
if(win==0)
{
printf("Seven! Sorry, you lost $%i.\n\n",bet+backbet);
money=money-(bet+backbet);
if(money<=0)
{
printf("Sorry you dont have the bills\n\n");
break;
}
if(point=1)
{
do
{
printf("Do you want to play again? y/n\n");
fflush(stdin);
scanf("%c\n",&choose);
}
while(choose != 'y' && choose != 'n');
if(choose=='y')
continue;
else if(choose=='n')
break;
}
}
else
{
printf("Congrats! You Win!\n");
switch(point)
{
case 6:
case 8:
gain=(int) (bet+(1.2*backbet));
printf("Here is a 6:5 pay! Thats $%i!\n\n",gain);
money+=gain;
break;
case 5:
case 9:
gain=(int) (bet+(1.5*backbet));
printf("Here is a 3:2 pay! Thats $%i!\n\n",gain);
money+=gain;
break;
case 4:
case 10:
gain=(int) (bet+(2*backbet));
printf("Here is a 2:1 pay! Thats $%i!\n\n",gain);
money+=gain;
break;
default:
printf("If this appears dana, youre screwed");
break;
}
do
{
printf("Do you want to play again? y/n.\n");
fflush(stdin);
scanf("%c\n",&choose);
}
while(choose!='y' && choose!='n');
if(choose=='y')
continue;
if(choose=='n')
break;
}
}
void rules();
{
printf("rules\n");
}
initbet()
{
int bet;
printf("\nYou have $%i.\n",money);
printf("Place your bet between 0 and 200 dollars\n");
fflush(stdin);
scanf("%i\n",&bet);
while(bet > money || bet < 0)
{
if(bet>money)
printf("Get outta here...you only have $%i! Bet again please\n",money);
else
printf("Bet again...loser");
fflush(stdin);
scanf("%i\n",&bet);
if(bet==0)
printf("You wimp...you bet nothing, but youre special, you can still play!\n");
else if(bet==money)
printf("Goin for it eh?Good luck, youll need it!\n");
}
}
roll();
{
int die1;
int die2;
int sum;
die1=rand()%6+1;
die2=rand()%6+1;
sum=die1+die2;
printf("\nRolling in progress...\nyou rolled a %i\n",sum);
return sum;
}
secbet(int bet); /*3*/
{
int backbet;
int high;
high= 2*bet;
if((money-bet) < high)
high = (money-bet);
printf("Place your backbet...\nIf you do not wish to make a backbet,enter 0\n");
printf("You can bet up to %i\n",high);
fflush(stdin);
scanf("%i\n",&backbet);
while(backbet>high || backbet<0)
{
if(backbet>high)
printf("No more than %i dollars please\n",high);
else
printf("Please type a valid bet\n");
fflush(stdin);
scanf("%i\n",&backbet);
}
return backbet;
}
char secroll(int point,int sum) /*2*/
{
int sum;
char win;
do
{
sum = roll(); /*1*/
}
while(sum!=point && sum!=7);
if(sum==point)
win = 1;
else
win = 0;
return win;
}
ok it is saying a bunch of stuff: (look above to see where it is)
1. error C2065: 'sum' : undeclared identifier
I dont understand cause i just declared it.
2.error C2143: syntax error : missing ';' before 'type'
It says this in numerous places and i dont understand why...
3.error C2059: syntax error : ')'
If anyone could fix or help me understand my errors, I would appreciate it a lot. Or if you see anything else that is sketchy. Thanks!