question about design and returning values from function.

B

Barry Schwarz

On Thu, 12 Sep 2013 13:15:22 +0200, Rosario1903

snip
the link i did read say 2,3,4,7,8 > 1,2,3,7,8
and 3,4,5,6,8 > 2,4,5,6,8

and already in the last version there is the just above >

but clubs<diamons<hearts<spades
should be easier to write... are you sure?
than clubs<diamons<hearts<spades
it has the same value for the 5th card of 2 couple example

2,2, 3, 3 and the last card 8 of spades
the other
2,2, 3, 3 and the last card 8 of clubs

so the first win... right? thank you

In evaluating poker hands, the suits have the same value. The hand is
a tie. Each takes half the pot. If the pot is odd, it is an informal
custom for the "higher suit" to take the odd chip. In other places,
the chip is left in the pot for the next hand or given to the dealer
as a tip.
 
H

Hans Vlems

anche se nn sono un grande programmatore, basti pensare che nn sono

riuscito a risolvere l'esercizio del K&R su un programma per indentare

codice C; nel mio piccolo nn sono come la massa, sono differente

[almeno spero]

e il mondo è bello perche' e' vario

I like variety too Rosario, but if one asks for support it sure helps to
clarify the issue :)
 
M

Michael Angelo Ravera

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 guaranteedto 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? :)

I like not to have an "else" when the "if" always returns. You just don't need it!

I like to catch the quick cases (like invalid arguments and special or easycases) early in the function and return. This lets you settle upon your main algorithm in the body knowing, for instance, that you won't be dividing by zero or running a loop with first > last.

In most cases, once I have passed through the argument validation and easy case filter phases, I will accumulate an answer and return only at the end.I do make exceptions to this when I run into "Oh shit!" situations, those that can only arise by interactions with other entities.

So, my style is "One Entry. One Exit after filter".

This is, however, a matter of style.
 
R

Rosario1903

On Tue, 10 Sep 2013 19:08:53 +0200, Rosario1903

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?

see no one but me like this argument i not post the final version,
afther i found some other bug...
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top