View Single Post
  #2   Spotlight this post!  
Unread 02-17-2006, 11:31 AM
xrabohrok's Avatar
xrabohrok xrabohrok is offline
hunter of errors
FRC #1208 (The Metool Brigade)
Team Role: Programmer
 
Join Date: Jan 2006
Location: O'Fallon
Posts: 62
xrabohrok is an unknown quantity at this point
Re: The silly syntax errors that won't go away!

Alrighty. I am pretty new to C, though not that new, and I have decided to attempt to try making my own libraries and attached .c files to see how they work. Through much thinking, I have decided to make a program that would simulate a blackjack deck. What I have here isn't very flexible, and it just draws five cards. But when I compile, it says everything in the .h file has been declared twice! I don't know what to do! Here's the code:

main.c
Quote:
#include <stdio.h>
#include <stdlib.h>

#include "deck.c"



int main(int argc, char *argv[])
{
int count=1;

draw(5);

while(count<=4)
{
if (hand[count]==0)
{break;}
printf("%s \n" ,handdis[count]);
count++;
}
system("PAUSE");
return 0;
}
deck.c

Quote:




//makes a random number between 1 and n
int randn(int n)
{
num=rand()%n + 1;
return num;
}

//the function that will give the value to the face cards
int facetovalue(int check)
{
//just use what you got in check for everything
//the ace checker
if (facev[check]==4)
{
printf("1 or 11?\n");
scanf("%i" ,&ace);
if (ace==1)
{
nface[check]--;
hand[handcount]=1;
handdis[handcount]= 1;
}
else if(ace==11)
{
nface[check]--;
hand[handcount]=11;
//handdis[handcount]= "11";
}
}

else
{
nface[check]--;
hand[handcount]=facev[check];
handdis[handcount]=face[check];
}

handcount++;
numface--;
return 0;
}

int draw(int drawn)
{

// draw this many cards
while (drawnn<=drawn)
{
//while codeing, I thought, what if there are no face cards left? Then we're screwed! so that's
//what's this is for
decision=1;
while (decision)
{
//what do we draw? face, or number card
randn(52);
if ((numdeckn>0)&&(num<36))
{

decision=0;
}
else if((numface>0)&&(num>37))
{

decision=0;
}
else
{
printf("Your out of cards!\n");
return 0;
}
}


if (num<=36)
{
//it's a number!
//caroline brought up something important, can one char store something like 10?
//We'll have to wait and find out.
randn(9);
hand[handcount]=deckn[num];
handdis[handcount]=deckn[num];
numdeckn--;
decknn[num]--;
handcount++;
return 0;

}

if (num>=37)
{

//it's a girl!
randn(4);
facetovalue(num);
return 0;
}
}
drawnn++;
}
deck.h

Quote:





//display face array
char face[5] = "0JKQA";

//number of face cards
int nface[5]= {0, 4, 4, 4, 4};

//default number of face cards
int dnface[5] = {0, 4, 4, 4, 4};

//values of face cards, where 4 is an ace
int facev[5] = { 0, 10, 10, 10, 4};

//is the ace one or 11?
int ace=1;

//number of cards in hand in array speak.
int handcount=0;

//what's in your hand, value wise
int hand[10]= {0,0,0,0,0,0,0,0,0,0};

//what's displayed
char handdis[10] ="0000000000";

//the temporary random number
int num=0;

//the values of the number
int deckn[10] = { 0, 2, 3, 4, 5, 6, 7, 8, 9, 10};

//the number of cards per type
int decknn[10] = { 0, 4, 4, 4, 4, 4, 4, 4, 4};

//the number of cards per type default
int decknnd[10] = { 0, 4, 4, 4, 4, 4, 4, 4, 4};

//the number of number cards left
int numdeckn=36;

//the number of face cards left
int numface=16;

//the deciding factor for figuring out if we are drawing from a viable pile
int decision=1;

//how many cards do you draw?
int cardn=0;

//how many cards we have drawn so far.
int drawnn=0;

the board didn't keep any of the formatting. Sorry!
__________________
"It's programming's fault" may be a viable excuse for just about everything, except the robot falling apart.

It will 'cause it can!

constants aren't. variables won't.