question about design and returning values from function.

G

gdotone

when writing a function that returns a value, should the value be return just
before the end brace of the function or does it not matter where in the
function the value is return from just as long as the value is guaranteed to be returned.

int function()
{
read in i /*protected from being anything other than a number, and 0 */
do ( i )
{
if ( i < 0)
return int_value
else
return int_value
}while
}

or is it better to

int function()
{
while ( condition)
{
if ( condition)
int_value = something; set some flag to end loop;
else
int_value = something else; set flag to end loop;
}
return int_value
}

also, is it better programming practice not to break out of a loop
or end a function with a return when a condition it set or found?

i hope you can understand my questions? :)

g.
 
E

Eric Sosman

when writing a function that returns a value, should the value be return just
before the end brace of the function or does it not matter where in the
function the value is return from just as long as the value is guaranteed to be returned.

Either will do. Some people like the "return only at end"
style, others prefer "don't add variables that amount to goto's."

One advantage of the "single return" style is that it's easy
to trace what's going on, if you need to while debugging:

int func(...) {
int result;
...
result = ...;
...
printf("result = %d\n", result); // added for debug
return result;
}

If there were multiple return statements you'd need to add a
printf() for each of them, and in a lengthy function you might
miss one. On the other hand, a fairly simple edit can add such
tracing to a multiple-return function:

static int Xfunc(...) { // formerly known as "func"
...
return this;
...
return that;
...
return theOther;
}

int func(...) { // new "func" calls Xfunc and traces it
int result = Xfunc(...);
printf("result = %d\n", result);
return result;
}

Personally, I've never found it difficult to handle the latter
transformation (at need), and prefer "return whenever it makes
sense" to adding variables that just obfuscate the intent.

BUT: This is largely a matter of taste, and tastes vary.
Write what seems clearest to you.
 
G

gdotone

Either will do. Some people like the "return only at end"
style, others prefer "don't add variables that amount to goto's."
One advantage of the "single return" style is that it's easy
to trace what's going on, if you need to while debugging:
int func(...) {
int result;
...
result = ...;
...
printf("result = %d\n", result); // added for debug
return result;
}
If there were multiple return statements you'd need to add a
printf() for each of them, and in a lengthy function you might
miss one. On the other hand, a fairly simple edit can add such
tracing to a multiple-return function:
static int Xfunc(...) { // formerly known as "func"
...
return this;
...
return that;
...
return theOther;
}
int func(...) { // new "func" calls Xfunc and traces it
int result = Xfunc(...);
printf("result = %d\n", result);
return result;
}
Personally, I've never found it difficult to handle the latter
transformation (at need), and prefer "return whenever it makes
sense" to adding variables that just obfuscate the intent.
BUT: This is largely a matter of taste, and tastes vary.
Write what seems clearest to you.

Thanks Eric.
 
Ö

Öö Tiib

when writing a function that returns a value, should the value be return
just before the end brace of the function or does it not matter where in
the function the value is return from just as long as the value is
guaranteed to be returned.

You should ask it from your local peers because it is style question.

If the peers are indifferent then try to pick what is simpler and more
robust in situation. Multiple exits may reduce need for local variables,
nested if-else blocks or simplify logical conditions. Single exit helps
to keep post-condition checks, roll-backs and cleanups in one place and
it is simpler to instrument it for debugging.

So both may simplify or complicate code depending on situation.
 
M

Malcolm McLean

when writing a function that returns a value, should the value be return
just before the end brace of the function or does it not matter where in
the function the value is return from just as long as the value is guaranteed
to be returned.
It's better to return a single value at the end. I use the identifier
"answer" for this purpose.
The reason is that if you have a single point of entry and a single
point of exit, its easier to maintain the code. If we want to add a
debug assert of the postconditions, we can do so immediately before the
return, and we know that the postconditions will be checked on every
execution path.

However it's sometimes difficult to write functions like that. Putting in
lots of nested if statements just to avoid a return isn't a good idea.
Also, often the return value indicates an error condition, and it can seem
natural to abort on error with a return ERRORCODE. C's also got the
problem that in functions that allocate several memory buffers,
it's better to have a separate section to free everything if an error
is encountered.

So there's not one answer.
 
J

James Kuyper

when writing a function that returns a value, should the value be return just
before the end brace of the function or does it not matter where in the
function the value is return from just as long as the value is guaranteed to be returned.

int function()
{
read in i /*protected from being anything other than a number, and 0 */
do ( i )
{
if ( i < 0)
return int_value
else
return int_value
}while
}

or is it better to

int function()
{
while ( condition)
{
if ( condition)
int_value = something; set some flag to end loop;
else
int_value = something else; set flag to end loop;
}
return int_value
}

The proponents of structured programming argue that every function
should have only a single exit point. Since reaching the end of a C
function block causes an implicit return if no explicit return statement
has been executed, that single exit would have to be at the end, that
corresponds to your first form. The idea is that having a single exit
should make it easier to understand a function's logic.

I learned structured programming early in my career, and I like and use
many of it's concepts, but not this one. I've found that the logic
tangle you have to create to force all exits into a single location
often obfuscates the code more than it clarifies it. This is
particularly true for error returns.

However, there's one context where I insist on the single-exit approach:
bookend code, such as malloc()/free() of fopen()/fclose(). I write such
code as follows:

int *pint = malloc(count * sizeof *pint);
if(pint==NULL)
{
// Error handling
}
else
{
// within this block of code, make no use of any construct
// would cause an exit from this block. No continue, break,
// goto, or longjmp() is allowed that goes outside the block,
// and no return, assert(), nor any call to any _Noreturn
// function.

free(pint);
}
also, is it better programming practice not to break out of a loop
or end a function with a return when a condition it set or found?

Breaking out of a loop early is conceptually the same issue as returning
from a function early, and I and the structured programmers have the
same disagreement about the best way to deal with it.
 
K

Kenny McCormack

Malcolm McLean said:
It's better to return a single value at the end. I use the identifier
"answer" for this purpose.
The reason is that if you have a single point of entry and a single
point of exit, its easier to maintain the code. If we want to add a
debug assert of the postconditions, we can do so immediately before the
return, and we know that the postconditions will be checked on every
execution path.

However it's sometimes difficult to write functions like that. Putting in
lots of nested if statements just to avoid a return isn't a good idea.
Also, often the return value indicates an error condition, and it can seem
natural to abort on error with a return ERRORCODE. C's also got the
problem that in functions that allocate several memory buffers,
it's better to have a separate section to free everything if an error
is encountered.

So there's not one answer.

You can get the desired result if you are willing to use a "goto" (Gasp!
Hush your ears! Did he say "goto"???). Then you can have a common exit
point at the end, where you can do your cleanup. And you use:

goto exit_here;

instead of "return;" when you need a quick exit.

It's like:
1) Quick exit - without convoluted if/else structures.
2) Single, common exit point at the end.
3) "goto-less" programming.

Choose 2!

(I.e., you can't have all 3, you can have any 2).

Note that most people, most of the time, choose to keep 1 & 3.

--
"The anti-regulation business ethos is based on the charmingly naive notion
that people will not do unspeakable things for money." - Dana Carpender

Quoted by Paul Ciszek (pciszek at panix dot com). But what I want to know
is why is this diet/low-carb food author doing making pithy political/economic
statements?

Nevertheless, the above quote is dead-on, because, the thing is - business
in one breath tells us they don't need to be regulated (which is to say:
that they can morally self-regulate), then in the next breath tells us that
corporations are amoral entities which have no obligations to anyone except
their officers and shareholders, then in the next breath they tell us they
don't need to be regulated (that they can morally self-regulate) ...
 
G

gdotone

Thanks everyone. It seems to me the best way for me to learn is
to ask for feedback from the actual code, too. I want to thank all of
you for this assistance. This is great.

I think the program does what the exercise ask for.

// C How to Program by Dietel and Dietel
// Exercise 7.13
//
//
// gdotone

/* This program comes from the exercises found in Dietel and Dietel
* C How to program. The execise calls for the modification of program
* found in fig. 7.24. The card dealing function is to deal two
* poker hands. Evaluate each hand and determine which hand is better.
*
* In this program Aces are not high. Dealers choice. :)
*
*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUMBEROFPLAYERS 2 /* changing this value does not add players */
#define NUMBEROFCARDSINHAND 5

/* prototypes */

void shuffle( int wDeck[][ 13 ] );

void deal( const int wDeck[][ 13], const char *wFace[],
const char *wSuit[], int aHand[][2], int otherHand[][2] );

int whichHandWins( int myHand[][2], int otherHand[][2] );

int isThere_A_Pair_In ( const int aHand[][2], int *kind );

int isThere_Two_Pair_In ( const int aHand[][2], int *kind );

int isThere_Three_Of_A_Kind_In ( const int aHand[][2], int *kind );

int isThere_Four_Of_A_Kind_In ( const int aHand[][2], int *kind );

int isThere_A_Flush_In ( const int aHand[][2] );

void bubbleSort( int aHand[][2] );

int isThere_A_Straight_In ( int aHand[][2]);

void printHand( const int aHand[][2], const char *wSuit[],
const char *Face[], int );

/***************************** main () ***************************************/

int main(int argc, const char * argv[])
{
/* initialize suit array */
const char *suit[ 4 ] = { "Hearts", "Dimonds", "Clubs", "Spades" };

/* initialize face array */
const char *face[ 13 ] = { "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };

/* declare and initialize deck array */
int deck[ 4 ] [13 ] = { 0 };

/* declare and intialize hand */
int playerOnesHand[5][2] = {0};
int playerTwosHand[5][2] = {0};

int playerOne = 1;
int playerTwo = 2;

/* declare and initialize pot */
int takeThePot = 0;

srand( (unsigned int) time( 0 ) ); /* seed random-number generator */

shuffle( deck ); /* shuffle the deck */

/* deal the Cards */
deal( deck, face, suit, playerOnesHand, playerTwosHand );

/* determine which hand wins the pot */
takeThePot = whichHandWins( playerOnesHand, playerTwosHand );

/* print winning hand and message */
if ( takeThePot == playerOne )
printHand (playerOnesHand, suit, face, playerOne);

else if ( takeThePot == playerTwo )
printHand ( playerTwosHand, suit, face, playerTwo );

else
printf("\n %s \n" ,
"Money stays in pot. Keep all hands above the table");

return 0;
}

/******************************** shuffle () *********************************/

/* suffle cards in deck */
void shuffle( int wDeck[][ 13 ] )
{
int row; /* row */
int column; /* colum number */
int card; /* counter */

/* for each of the 52 cards, choose slot of deck randomly */
for ( card = 1; card <= 52; card++ )
{
/* choose new random location until unoccupide slot found */
do {
row = rand() % 4;
column = rand() % 13;
} while ( wDeck[row][column] != 0 ); /* end do ... while */

/* place card number in chosen slot of deck */
wDeck[ row ][ column ] = card;

} /* end for ( card = 1 ... ) */

} /* end shuffle */

/********************************* deal() ************************************/

/* deal cards in deck */
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[], int aHand[][2], int anotherHand[][2] )
{
int card; /* card counter */
int row; /* row counter */
int column; /* column counter */
int t = 0; /* t used as row index for myHand */
int u = 0; /* u used as row index for otherHand */

/* deal cards, poker hand */
for ( card = 1; card <= NUMBEROFCARDSINHAND * NUMBEROFPLAYERS; card++ )
{
/* loop through rows of wDeck */
for ( row = 0; row <= 3; row++ )
{
/* loop through columns of wDeck for current row */
for ( column = 0; column <= 12; column++ )
{
/* if slot contains current card, display card */
if ( wDeck[row][ column] == card)
{
if ( card % 2 )
{
aHand[t][0] = column;
aHand[t][1] = row;
printf( "%5s of %-8s\t", wFace[ column ], wSuit[ row ] );
t++;
} /* end if ( card % 2 ) */
else
{
anotherHand[0] = column;
anotherHand[1] = row;
printf( "%5s of %-8s\n", wFace[ column ], wSuit[ row ] );
u++;

} /* end else ( card % 2 ) */
}

}/* end for ( column = 0 ...) */

} /* end for ( row = 0 ...) */

} /* end for ( card = 1 ...) */

printf("\n");

} /* end void deal(... ) */

/********************* isThere_A_Pain_In () ******************************/

int isThere_A_Pair_In (const int aHand[][2], int *kind )
{
int strenghtOfHand;
int col = 0;

for ( int i = 0; i < NUMBEROFCARDSINHAND; i++ )
for ( int j = i + 1; j < NUMBEROFCARDSINHAND; j++ )
if ( aHand[col] == aHand[j][col] )
{
*kind = aHand[col];

/*
* printf( "Found a pair\n");
* printf( " %d\n", *kind );
*/

return strenghtOfHand = 1;
} /* found a pair */

return strenghtOfHand = 0; /* no pair found */

} /* end isThere_A_Pair_In () */

/********************* isThere_Two_Pair_In () ******************************/

int isThere_Two_Pair_In ( const int aHand[][2], int *kind )
{
int col = 0;
int numberOfPairs = 0; /* number of pairs found in hand */
int strenghtOfHand;
int firstPair, secondPair;

/* look for first pair */
for (int i = 0; i < NUMBEROFCARDSINHAND; i++ )
for ( int j = i + 1; j < NUMBEROFCARDSINHAND; j++ )
if ( aHand[col] == aHand[j][col] )
{
numberOfPairs++;
firstPair = aHand[col];

/* looking for the next pair */
for ( int k = i + 1; k < NUMBEROFCARDSINHAND; k++ )
for ( int m = k + 1; m < NUMBEROFCARDSINHAND; m++ )
if( ( aHand[k][col] == aHand[m][col])
&& ( aHand[k][col] != aHand[j][col]))
{
numberOfPairs++;
secondPair = aHand[k][col];
/* printf( "This hand has two of a kind" ); */
if (firstPair > secondPair)
*kind = firstPair;
else if (firstPair < secondPair)
*kind = secondPair;
else
*kind = firstPair; /* or secondPair, both are equal */

return strenghtOfHand = 2;
}

} /* end if ( ahand[0] ... ) */

return strenghtOfHand = 0; /* two pair not found */

} /* end isThere_Two_Pair_In() */

/********************* isThere_Three_Of_A_Kind_In () ***********************/

int isThere_Three_Of_A_Kind_In ( const int aHand[][2], int *kind )
{
int strenghtOfHand;
int col = 0; /* need not change, only looking at the face of the card */

for ( int i = 0; i <= NUMBEROFCARDSINHAND; i++ )
for ( int j = i + 1; j < NUMBEROFCARDSINHAND; j++ )
if ( aHand[col] == aHand[j][col] )
{
/* find next card of same kind */
for (int k = j + 1; k < NUMBEROFCARDSINHAND; k++)
{
if ( aHand[col] == aHand[k][col]) /* found third kind match */
{
*kind = aHand[col];
/* printf( "\nThere are three of a kind in hand\n"); */
return strenghtOfHand = 3;
} /* end if ( aHand[col] ... ) */

} /* end for ( int k = j + 1; ... */

} /* end if ( aHand[col]...) */

return strenghtOfHand = 0; /* no three of a kind */

} /* end isThere_Three_Of_A_Kind_In () */

/********************* isThere_Four_Of_A_Kind_In () ************************/

int isThere_Four_Of_A_Kind_In ( const int aHand[][2], int *kind )
{
int strenghtOfHand;
int col = 0;

for ( int i = 0; i <= NUMBEROFCARDSINHAND; i++ )
for ( int j = i + 1; j < NUMBEROFCARDSINHAND; j++ )
if ( aHand[col] == aHand[j][col] )
{
/* find next card of same kind */
for (int k = j + 1; k < NUMBEROFCARDSINHAND; k++)
{
if ( aHand[col] == aHand[k][col]) /* found third kind */
{
/* find next card of same kind */
for (int m = k + 1; m < NUMBEROFCARDSINHAND; m++ )
if ( aHand[col] == aHand[m][col] )
{
*kind = aHand[col];
/* printf( "This hand has four of a kind"); */
return strenghtOfHand = 4;
}

} /* end if ( aHand[col] ... ) */

} /* end for (int k = j + 1 ... ) */

} /* end if ( aHand[col] ... ) */

return strenghtOfHand = 0; /* four of a kind not found in hand */

} /* end isThere_Four_Of_A_Kind_In () */

/************************** isThere_A_Flush_In () ****************************/

int isThere_A_Flush_In ( const int aHand[][2] )
{
int strenghtOfHand;

int col = 1;

for ( int j = 2; j < NUMBEROFCARDSINHAND ; j++ )
{
if ( aHand[0][col] != aHand[j][col] ) /* each kind must be the same */
return strenghtOfHand = 0;
/* kind = hearts, spades, etc. */
} /* end for */

/* printf( "\nI've got a flush\n"); */

return strenghtOfHand = 5;

} /* end isThere_A_Flush_In() */

/************************* isThere_A_Straight () *****************************/

/* A flush must exist, all cards of the same suit,
* if a flush exist, put hand in face value order
* Aces low (dealers choice)
*/

int isThere_A_Straight_In ( int aHand[][2] )
{
int col_1 = 1; /* is used to check kind between cards */
int col_2 = 0; /* is used to check face value */
int strenghtOfHand;
int difference = 0;

for ( int j = 1; j < NUMBEROFCARDSINHAND ; j++ )
{
if ( aHand[0][col_1] != aHand[j][col_1] ) /* each kind must be the same */
return strenghtOfHand = 0;

} /* end for ( j = 1; ... ) */

bubbleSort( aHand );

for (int i = 0; i < NUMBEROFCARDSINHAND - 1; i++)
{

difference = aHand[i+1][col_2] - aHand[col_2];

if (difference != 1 )
{
return strenghtOfHand = 0;
} /* end if (difference ... ) */

} /* for ( int i = 0; ...) */

/*
* printf ( "%s\n%s\n", "just put your money on in my Pocket",
" no need to rest it on the table");
*/
return strenghtOfHand = 6;

} /* end isThere_A_Straight () */

/************************* bubblesort() *************************************/
/* This bubble sort is taken from Dietel and Dietel fig 6.16 and modified
* to handle a 2-D array cosisting of two columns.
*/

void bubbleSort( int aHand[][2] )
{
int pass; /* pass counter */
int j; /* comparison counter */
int hold; /* temporary location used to swap elements */
int col = 0;

/* loop to control number of passes */
for ( pass = 1; pass < NUMBEROFCARDSINHAND; pass++ )
{
/* loop to control number of comparisons per pass */
for ( j = 0; j < NUMBEROFCARDSINHAND - 1; j++ )
{
/* swap element if out of order */
if ( aHand[j][col] > aHand[ j + 1 ][col] )
{
hold = aHand[ j ][col];
aHand[ j ][col] = aHand[ j + 1 ][col];
aHand[ j + 1][col] = hold;
} /* end if */

} /* end inner for */

} /* end outer for */

} /* end function bubbleSort */

/***************************** printHand() ***********************************/

void printHand( const int aHand[][2], const char *wSuit[],
const char *wFace[], int player )
{
int col = 0; /* column relates to suit of card */

printf ("\n\n %s\n\n","This hand wins the pot.");

for (int row = 0; row < NUMBEROFCARDSINHAND; row++)
printf (" %-6s of %-8s\n", wFace[ aHand[row][col] ],
wSuit[ aHand[row][col + 1] ]);

printf("\n\n%s",
(player==1)? " Player One Wins": " Player Two Wins");


printf("\n");
}

/******************************** whichHandWins() ****************************/

int whichHandWins( int aHand[][2], int anotherHand[][2] )
{
int evaluateTheHand( int aHand[][2], int *kind );

int aHandsValue;
int anotherHandsValue;
int aHandsKind;
int anotherHandsKind;

/* evaluate hand */
aHandsValue = evaluateTheHand(aHand, &aHandsKind);
anotherHandsValue = evaluateTheHand(anotherHand, &anotherHandsKind);

/* determine which hand wins and return winning hand */
if ( anotherHandsValue > aHandsValue )
return 2; /* anotherHand wins, correponds to second player's hand */

else if ( anotherHandsValue < aHandsValue )
return 1; /* aHand wins, correponds to first player's hand */

else if ( (anotherHandsValue == aHandsValue) && (anotherHandsValue != 0) )
{
/* look at the value of the matching cards */
if ( anotherHandsKind > aHandsKind )
return 2; /* anotherHand wins, correponds to second player's hand */

else if ( anotherHandsKind < aHandsKind )
return 1; /* aHand wins, correponds to first player's hand */

else
return 0; /* otherwise both, ...Kind,kinds are equal */
/* this return not neccessary */
} /* end else if ( anotherHandsValue ... ) */

else
return 0;
}


/****************************** evaluateTheHand () ****************************/

int evaluateTheHand ( int aHand[][2], int *kind )
{
int value = 0;


if ( (value = isThere_A_Straight_In(aHand)) )
{
return value;
}
else if ( (value = isThere_A_Flush_In(aHand)) )
{
return value;
}
else if ( (value = isThere_Four_Of_A_Kind_In(aHand, kind)) )
{
return value;
}
else if ( (value = isThere_Three_Of_A_Kind_In(aHand, kind)) )
{
return value;
}
else if ( (value = isThere_Two_Pair_In(aHand, kind)) )
{
return value;
}
else if( (value = isThere_A_Pair_In(aHand, kind)) )
{
return value;
}

return value;

} /* end int evaluateTheHand ( ... ) */
 
G

glen herrmannsfeldt

(snip)
The proponents of structured programming argue that every function
should have only a single exit point. Since reaching the end of a C
function block causes an implicit return if no explicit return statement
has been executed, that single exit would have to be at the end, that
corresponds to your first form. The idea is that having a single exit
should make it easier to understand a function's logic.

Yes. The goal should be the ability to understand the logic.

Now, it might be that not everyone understands it the same way,
but often enough one way or the other is enough easier to understand.
I learned structured programming early in my career, and I like and use
many of it's concepts, but not this one. I've found that the logic
tangle you have to create to force all exits into a single location
often obfuscates the code more than it clarifies it. This is
particularly true for error returns.

(snip)

-- glen
 
M

Malcolm McLean

On Wed, 4 Sep 2013 08:09:18 -0700 (PDT), (e-mail address removed) wrote:


i have not understood well what is a card...

what is a card?

what is a deck?

can have a deck less of 32 cards?

i find easy represent a card as one u32
and deck one array of u32, when deck[0] is the number of card has the
deck[]
A playing card is a rectangular piece of stiffened paper used for playing
games.
A full set of cards is called a "deck". Western playing cards consist of
four suits, or symbols, hearts, clubs, diamonds and spades. There are
pip cards numbers 1 to 10, and court cards, jacks, queens and kings.
The single pip is called the Ace.
So there are 13 times 4 or 52 cards in the standard deck. There's also a
joker or extra card, used only in a minority of games.

You can represent cards in several ways in C programs, depending on whether
clarity or efficiency is your goal.
 
G

gdotone

On Thu, 05 Sep 2013 19:02:15 +0200, Rosario1903

I don't know all the rules of the game, poker.

The next exercise in the book ask for a dealer to be created and the
dealer needs to be able to replace 1,2, or 3 cards in his hand and revaluate
the hand. Actually that doesn't seem too hard, but the logic as to which
cards to replace does. ( I know the objective, get a better hand )

So, since I'm not a poker player, I decided to see if I could see a game and
determine when the dealer should do that.
To make a longer story longer, sorry, I went to www.shockwave.com and looked up
poker.
I found Governor of Poker 2. So, to see what a card is, and a deck, you may check it out.

The game is not the exact same one being ask for in the exercises, though.
To see the game or play it you will have to watch a movie advertisement, 30 seconds,
but it was very informative, the game, not the movie trailer. Watching the game
made me believe with a little more C knowledge, well, maybe a lot more,
I could write a program that looks and plays as good as that one.

http://www.shockwave.com/gamelanding/governor-of-poker-2.jsp

:)
g.
 
I

Ian Collins

Rosario1903 said:
this would be a little better...

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

#define R return

Run away!
 
K

Keith Thompson

Rosario1903 said:
this would be a little better...

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

#define R return
#define W while
#define F for
#define P printf
#define G goto
[...]

As always, this is where I stop reading.

Please stop wasting our time with this illegible crap.
 
G

glen herrmannsfeldt

(snip)
Run away!

I suppose so, but it looks like from the comments that the writer
is not a native English speaker.

I suppose he/she could have #define to be the appropriate words
in the native language, but R might be meaningfull enough.

-- glen
 
G

glen herrmannsfeldt

but if 2 people play poker
and one has in his hands 2,3,4 of harts and 7,8 of Spades
the other one has in his hands 1,2,3 of spades and 7,8 of harts
who win the first or the second? or both?

Normally, if both have the same type of hand, there is a rule for
which cards count. If hte same number, then the suits rank
clubs, diamonds, hearts, spades, in increasing order.

-- glen
 
H

Hans Vlems

Op donderdag 12 september 2013 10:38:00 UTC+2 schreef Rosario1903:
increase means spades>harts if seen it as score?

Yes, think of bridge.

You use define's to provide shorthands for reserved words.
C allows that but please understand that this makes you just about
the only person on this planet who can easily read the program.
And I guess you can do that because this style of programming
is very familiar to you, right?
The rest of the world doesn't have your experience and cannot easily
read your code, let alone provide help. So unless you're the best programmer
in the world, please get rid of those #define's.
Hans
 
J

James Kuyper

(snip)



I suppose so, but it looks like from the comments that the writer
is not a native English speaker.

I suppose he/she could have #define to be the appropriate words
in the native language, but R might be meaningfull enough.

Those macros make his programs unreadable nightmares.
 
G

guinness.tony

Normally, if both have the same type of hand, there is a rule for
which cards count. If hte same number, then the suits rank
clubs, diamonds, hearts, spades, in increasing order.

-- glen

This doesn't seem "normal" to me. In poker, the suits are disregarded
save for determining whether a flush is present in a hand.

http://en.wikipedia.org/wiki/List_of_poker_hands

(Para beginning "the suits of the cards...")

When two or more hands are face-value identical, they rank equally
(unless one is a flush and the other is not).
If they are winning hands, the prize is divided equally among their
holders.
 
J

Joe Pfeiffer

#define R return
#define W while
#define F for
#define P printf
#define G goto
#define u32 unsigned
#define i32 int
#define u8 unsigned char
#define i8 signed char

<snip>

My eyes! My eyes!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top