I got this code (written when sleepy, sorry for lack of "expertness")
#include <stdio.h>
#include<time.h>
int card1; int card2; int card3;
int total;
int other;
srand(time(NULL));
card1=(rand()%22)+1;
card2=(rand()%22)+1;
other=(rand()%22)+1;
total=card1+card2;
int main()
{
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);
if(total<21)
{ turn(); }
else if (total>21);
{ printf("BUST! play again?\n"); }
return 0;
}
#include<stdio.h>
void turn();
void turn()
{ char ans;
printf("Twist or bust (t/b)\n");
ans = getchar();
switch(ans)
{ case 't' : draw(); break;
case 'b' : neg(); break;
}
}
#include <stdio.h>
void neg();
void neg()
{
if(total > other)
{ printf("you won! play again?\n"); }
else if (other > total)
{printf("damn nice try. play again?\n"); }
}
#include<stdio.h>
void draw();
void draw()
{
srand(time(NULL));
card3=(rand()%22)+1;
total+=card3;
}
it's a card game (twist or bust). so two random numbers are drawn, if they're over 21, you lose, under and you can take another card. if the three cards are over 21 you lose, if not anohter card.. so the total is always changing, how can i pass the value of "total" between the functions? i know there's a way in java placing the variable name in the () of the method, (well i think. it didn't work but i'm new at all of this). any pointers would be appriciated, but like i said, sleepy when i wrote it :confused: