Go to Post Public Service Announcement: Pressing the spacebar when the robot is enabled isn't nearly as funny the forty-second time. - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 17-02-2006, 11:31
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.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
C18 v2.4 -- Syntax error where there is no syntax error Joel J Programming 7 12-01-2007 17:27
Union Errors in AutoCAD indieFan Inventor 4 16-07-2004 12:54
PBASIC language syntax WizardOfAz Programming 14 30-04-2003 10:23
Digital inputs, bandwith, errors? Micah Brodsky Programming 7 20-01-2003 16:08
Specs full of errors??? Simon G Motors 1 20-01-2003 12:53


All times are GMT -5. The time now is 15:31.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi