I moved those three lines an it worked! except the first two numbers totaled 23 so it went straight out.. guess i should get to work on the switch statements eh? thanks for the help
Aia, a copy is being passed, that makes sense. so the total in main is total(copy1), that gets sent to turn but as total( copy2). So if i sent it back to the main (for the if>21 evaluation) would it be total(copy1) or total(copy2)thats evaluated?
#include <stdio.h>
#include<time.h>
void turn(int total, int other);
void draw(int total, int other);
void neg(int total, int other);
void eval(int total, int other);
int main()
{
int card1; int card2; int card3;
int total;
int other;
srand(time(NULL));
card1=(rand()%13)+1;
card2=(rand()%13)+1;
other=(rand()%13)+1;
total=card1+card2;
printf("Hey, welcome to HBK's Twist or bust game. Lets begin\n");
printf("Your cards are: %d and %d\n", card1, card2);
printf("total is: %d\n", total);
eval(total, other);
return 0;
}
void eval(int total, int other)
{ char again;
if(total<21)
{ turn(total, other); }
if (total>21);
{ printf("BUST! play again?\n"); }
again = getchar();
while (getchar() != '\n');
switch(again)
{ case 'y' : main(); break;
case 'n' : printf("ok, see ya!\n"); break;
}
}
void turn(int total, int other)
{ char ans;
printf("Twist or bust (t/b)\n");
ans = getchar();
while (getchar() != '\n');
switch(ans)
{ case 't' : draw(total, other); break;
case 'b' : neg(total, other); break;
}
}
void draw(int total, int other)
{
srand(time(NULL));
int card3=(rand()%13)+1;
printf("next card is: %d\n", card3);
total+=card3; printf("new total: %d\n", total);
total=(int) total; eval(total, other);
}
void neg(int total, int other)
{ char win, lose;
if(total > other)
{ printf("Opponents cards: %d\n", other);
printf("you won! play again?\n");
win = getchar();
while (getchar() != '\n');
switch(win)
{ case 'y' : main(); break;
case 'n' : printf("ok, see ya!\n"); break;
}}
else if (other > total)
{printf("Opponents cards: %d\n", other);
printf("damn nice try. play again?\n");
lose = getchar();
while (getchar() != '\n');
switch(lose)
{ case 'y' : main(); break;
case 'n' : printf("ok, see ya!\n"); break;
}}
}
thats the new one. here's a game:
Hey, welcome to HBK's Twist or bust game. Lets begin
Your cards are: 3 and 5
total: 8
Twist or bust? (t\b):
t
next card is: 10
new total: 18
BUST! play again?
n
ok, see ya!
BUST! play again?
n
ok, see ya!
BUST! play again?
It got stuck in a loop :-\ . if i don't twist and say no. then it exits as it should. why does it jump back up to the eval function?
now it's getting interesting :-D