Skip to main content
GameDev.net gamedev.net
🔒 Locked

Parse errors

Started by grahamhinchly Jan 10, 2001 at 9:58 AM 1 replies 400+ views
Original Post
grahamhinchly
grahamhinchly
This code produces 3 parse errors: c:\my documents\2 card draw source.c: In function `playerCards'': c:\my documents\2 card draw source.c:146: parse error before `dealerCards'' c:\my documents\2 card draw source.c:187: parse error before `int'' c:\my documents\2 card draw source.c:223: parse error at end of input Why does it do this? I have tweaked and fiddled but it still doesn''t work! Thanks for your time, it''s greatly appreciated. Graham #include #include #include #include #include #define Jack 11 #define Queen 12 #define King 13 char suit[10]; int dnumCard1; int dnumCard2; int cards = 13; char * dsuitname[10]; char * dsuitnameb[10]; int numCard1; int numCard2; int suits = 4; int suita; int suitb; int dsuita; int dsuitb; char * suitname[10]; char * suitnameb[10]; char name[30]; int total; int dtotal; int error = 0; int bet; int bank = 220; int msg; int wime; main() { while (bank > 0) { welcome(); clear(); flumpy(); clear(); playerCards(); dealerCards(); result(); } system("PAUSE"); return 0; } welcome() { printf("Hello and Welcome to 2 Card Draw!!\n"); printf("Please enter your name: "); scanf(" %s", &name); printf("\nThank You.\n"); printf("We hope you enjoy your evening, %s!\n", name); system("PAUSE"); error = 1; return 0; } clear() { int clear; for(clear = 0; clear < 25; clear++) { printf("\n"); return 0; } } flumpy() { printf("It''s risky this two card draw. You have $220.\n"); printf("You double your dosh if you win.\n"); printf("Dealer wins if the cards value is equal\n"); bank = 220; printf("Place you bet: "); scanf(" %d", &bet); while(bet >> bank) { printf("\nYou have entered an illegal amount.\n Please re-enter your amount or press x to exit."); scanf(" %d", bet); if(bet == ''x'') { exit(1); } bank -= bet; printf("You have %d left in the bank\n", bank); system("PAUSE"); return 0; } } playerCards() { numCard1 = (rand() % 13); numCard2 = (rand() % 13); if (numCard1 == numCard2) { numCard2 -= 1; } do {suita = (rand() % (suits)); switch(suita) {case (1) : strcpy((char *)suitname,"Diamonds"); break; case (2) : strcpy((char *)suitname,"Hearts"); break; case (3) : strcpy((char *)suitname,"Spades"); break; default : strcpy((char *)suitname,"Clubs"); break; } ; do {suitb = (rand() % (suits)); switch(suitb) {case (1) : strcpy((char *)suitnameb,"Diamonds"); break; case (2) : strcpy((char *)suitnameb,"Hearts"); break; case (3) : strcpy((char *)suitnameb,"Spades"); break; default : strcpy((char *)suitnameb,"Clubs"); break; }; return 0; } dealerCards(); { dnumCard1 = (rand() % (cards)); dnumCard2 = (rand() % (cards)); if (dnumCard1 == dnumCard2) { dnumCard2 -= 1; } do {suita = (rand() % (suits)); switch(suita) {case (1) : strcpy((char *)suitname,"Diamonds"); break; case (2) : strcpy((char *)suitname,"Hearts"); break; case (3) : strcpy((char *)suitname,"Spades"); break; default : strcpy((char *)suitname,"Clubs"); break; }; do {suitb = (rand() % (suits)); switch(suitb) {case (1) : strcpy((char *)suitnameb,"Diamonds"); break; case (2) : strcpy((char *)suitnameb,"Hearts"); break; case (3) : strcpy((char *)suitnameb,"Spades"); break; default : strcpy((char *)suitnameb,"Clubs"); break; }; return 0; ; int result(int) { printf("\nWell, here comes the moment of truth...\n"); sleep(2); printf("You got the %s of %s and the %s of %s.\n", numCard1, suitname, numCard2, suitnameb); printf("The dealer got %s of %s and the %s of %s\n", dnumCard1, dsuitname,dnumCard2, dsuitnameb); printf("Hang on, that means....\n"); total = numCard1 + numCard2; dtotal = dnumCard1 + dnumCard2; sleep(2); printf("You got %d and dealer got %d. ", total, dtotal); if (total >> dtotal) { bank += bet; printf("You win!!! You now have $%d\a", bank); system("PAUSE"); return 0; } else { bank -= bet; printf("You lose. Your balance now rests on $%d.\n Press 1 to exit.", bank); msg = getchar(); if (msg == 1) { exit(1); } if (bank << 0) { printf("You are in minus figures."); system("PAUSE"); exit(1); }; }; }
We were all beginners once, don't forget that...
Ironblayde
Ironblayde
It''s hard to tell since there''s no indentation and I didn''t spend too much time looking at it, but it looks like your curly braces { } don''t match up. Usually I''d expect that to produce something other than "parse error" but that depends on the compiler, so you might want to check that. I''m guessing the lack of indentation just comes from the fact that HTML won''t print successive spaces unless you''re inside a <PRE> tag, but if that''s really what your code looks like, fix it.

-Ironblayde
 Aeon Software

Next thing you know, they''ll take my thoughts away.
"Your superior intellect is no match for our puny weapons!"
ImmaGNUman
ImmaGNUman
You might also want to consider giving your functions return values(just fugly that way), and it probably is braces.

Try indenting, then see if the braces are aligned(think the error is after the suitA do loop).

Also, you might want to avoid that many global variables, just for the sake of readability. But, work on your style, it will probably get better as you learn that bigger programs are harder to program without decent style, nevermind lack of comments.

-----------------------------

A wise man once said "A person with half a clue is more dangerous than a person with or without one."

The Micro$haft BSOD T-Shirt
-----------------------------A wise man once said "A person with half a clue is more dangerous than a person with or without one."The Micro$haft BSOD T-Shirt

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.