Computer Science Canada Function Failing to Give a Result |
Author: | SwAnK [ Thu Apr 21, 2005 4:05 pm ] | ||
Post subject: | Function Failing to Give a Result | ||
Here is my function, I was trying to create that if a straight was rolled with 5 dice then so many points were awarded, when executed, it states that my function is failing to give a result. Can someone show me why? Here is my code
thanx |
Author: | Token [ Thu Apr 21, 2005 4:34 pm ] |
Post subject: | |
okay, i dont see how that could help you doing it that way, you should probibly order them by size, (not sure how to do that) and then check to see if the seccond one is 1 less than the first, and if that is true 4 times then its a small straight and 5 times its a large straight ... providing that your going for some sort of yatzee thing |
Author: | wtd [ Thu Apr 21, 2005 4:41 pm ] | ||||
Post subject: | |||||
A few things here:
false, by it's very nature, isn't true. This elsif will never happen. |
Author: | Cervantes [ Thu Apr 21, 2005 4:41 pm ] | ||
Post subject: | |||
You're function fails to give a result if
is false. You need something to result in an 'else' part of that if statement. No matter what, your function needs to give a result. This could also be achieved by having a 'result something' at the end of the procedure. Note that this doesn't mean that that result will always be returned, because if the function reaches a result line earlier in the code, it will terminate and result that value immediately. Thus, the last result line is only reached under certain conditions. |
Author: | SwAnK [ Thu Apr 21, 2005 10:50 pm ] |
Post subject: | |
so then what can i put for my else statment?? ![]() |
Author: | Tony [ Fri Apr 22, 2005 8:32 am ] | ||
Post subject: | |||
SwAnK wrote: so then what can i put for my else statment??
![]() well if it's not returning true from the if part, I'm going to assume that you want
|
Author: | wtd [ Fri Apr 22, 2005 5:55 pm ] | ||||||||
Post subject: | |||||||||
Tony wrote: SwAnK wrote: so then what can i put for my else statment??
![]() well if it's not returning true from the if part, I'm going to assume that you want
It should be noted that this, while Tony means well, is bad code. When you write the "if" statement (and it's accompanying "else", the condition is either true or false. That's your boolean value right there. So instead of that, let's just say:
Consider a real example:
vs.
|
Author: | Tony [ Fri Apr 22, 2005 6:12 pm ] |
Post subject: | |
wtd wrote: It should be noted that this, while Tony means well, is bad code.
Indeed it is. On it's own. That was provided as a reference structure to use, since SwAnK also had some attempts at counter+ type of thing.. ![]() |