Wrox Programmer Forums
|
BOOK: Beginning iOS Game Development
This is the forum to discuss the Wrox book Beginning iOS Game Development by Patrick Alessi ; ISBN: 978-1-1181-0732-4
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning iOS Game Development section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2012, 07:50 PM
Registered User
 
Join Date: Jul 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in Acey-Deucy

Hello, I get an error when trying to lunch the program "Parse Issue expected ")"

Here is the code error is marked with red face

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

struct card {
char* name;
char* suit;
int value;
};

void shuffle(struct card* deck) {
// Seed the random number generator
srandom( time( NULL ) );
int i=0;
int randomA, randomB;
struct card tempCard;

do {
// Generate 2 random numbers to determine which cards to swap
randomA = random() % 52;
randomB = random() % 52;

if (randomA == randomB)
{
continue;
}

// Swap slots A and B
tempCard = deck[randomA];
deck[randomA] = deck[randomB];
deck[randomB] = tempCard;

// Increment the counter
i++;
}
while (i<1000000);

}

void printDeck(struct card* deck) {
// Print out the shuffled deck

while (deck->value!=0) {
printf("The card is %s of %s\n", deck->name,
deck->suit);

// Move to the next card
deck++;

}
}


int main (int argc, const char * argv[])
{

struct card deck[] =
{
{"ace", "spades",1}, {"two", "spades",2}, {"three", "spades",3},
{"four", "spades",4}, {"five", "spades",5}, {"six", "spades",6},
{"seven", "spades",7}, {"eight", "spades",8}, {"nine", "spades",9},
{"ten", "spades",10}, {"jack", "spades",11}, {"queen", "spades",12},
{"king", "spades",13},
{"ace", "clubs",1}, {"two", "clubs",2}, {"three", "clubs",3},
{"four", "clubs",4}, {"five", "clubs",5}, {"six", "clubs",6},
{"seven", "clubs",7}, {"eight", "clubs",8}, {"nine", "clubs",9},
{"ten", "clubs",10}, {"jack", "clubs",11}, {"queen", "clubs",12},
{"king", "clubs",13},
{"ace", "hearts",1}, {"two", "hearts",2}, {"three", "hearts",3},
{"four", "hearts",4}, {"five", "hearts",5}, {"six", "hearts",6},
{"seven", "hearts",7}, {"eight", "hearts",8}, {"nine", "hearts",9},
{"ten", "hearts",10}, {"jack", "hearts",11}, {"queen", "hearts",12},
{"king", "hearts",13},
{"ace", "diamonds",1}, {"two", "diamonds",2}, {"three", "diamonds",3},
{"four", "diamonds",4}, {"five", "diamonds",5}, {"six", "diamonds",6},
{"seven", "diamonds",7}, {"eight", "diamonds",8},
{"nine", "diamonds",9},{"ten", "diamonds",10}, {"jack", "diamonds",11},
{"queen", "diamonds",12}, {"king", "diamonds",13},
{"sentinel", "null", 0}
};

// Create the player's bank and start it off with 100 credits
int bank=100;

// Create a pointer to the deck
struct card* pDeck = deck;

// Create a variable to hold the bet
int bet=0;

// Run the function to shuffle the deck
shuffle(deck);

// Run the gmae in a loop. Continue as long as the bank is > and none of
// the next three cards are sentinel
do {
// Print the amount of credits in the bank
printf("Your bank: %i\n,", bank);

// Print the cards
printf("The cards: ");

// First Card
printf("%s of %s ", pDeck->name, pDeck->suit);

// Move to the next card
pDeck++;

// Second card
printf("and %s of %s\n", pDeck->name,pDeck->suit);

// Move the pointer to the next card
pDeck++;

// Ask for the bet
// Do this in a loop because we cannot accept bets greater than the
// amount that the player has in the bank and we cannot
// accept a 0 bet
do {
printf("Enter your bet: ");
scanf("%i", &bet);


}
while (bet <= 0 || bet> bank);

// Draw the third card
printf("The third card is %s of %s\n", pDeck->name, pDeck->suit);

// Determine if the player won
// The player is a winner if the third card falls between the first two
// Ties go to the house
if (((pDeck-2)->value < pDeck-> value &&
(pDeck-1)->value > pDeck->value) ||
((pDeck-2)->value > pDeck-> value &&
(pDeck-1)->value < pDeck->value)) {
printf("We have a winner!\n\n");

// Player won, add bet to the bank
bank+= bet;
}

else {
printf("Sorry, you lose.\n\n");
// Player lost, sybsrct bet from bank
bank -= bet;
}

// Move to the next card
pDeck++;

}
while (bank >0 &&
pDeck->value!-0 &&
(pDeck+1)->value!=0 &&
(pDeck+2)->value!=0 ;

// The game is over
printf("The game is over. Your final score is %i\n", bank);


return 0;
}


I get the error where the angry face is.
 
Old July 11th, 2012, 12:34 AM
Friend of Wrox
 
Join Date: Aug 2010
Posts: 298
Thanks: 1
Thanked 62 Times in 60 Posts
Default

There are 2 errors in your while statement

Code:
while (bank >0 &&
           pDeck->value!-0 &&
           (pDeck+1)->value!=0 &&
           (pDeck+2)->value!=0 ;
////the following line is incorrect
pDeck->value!-0 &&
it should be
pDeck->value!=0 &&

The parse error is caused by a missing closing bracket
(pDeck+2)->value!=0 ;
should be
(pDeck+2)->value!=0);


Bob





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 3: Acey Deucy problem thunderous BOOK: Beginning iOS Game Development 2 May 16th, 2012 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.