This would seem to boil down to a single
loop, here with various syntactical decoration.
program zammit
version 8
args games points garbage
if "`garbage'" != "" | "`points'" == "" | "`games'" == "" {
di as err "syntax: zammit #games #points"
error 198
}
confirm integer num `games'
confirm integer num `points'
cap assert `points' <= 3 * `games'
if _rc {
di as err "too many points"
error 498
}
cap assert `points' >= 0 & `games' >= 1
if _rc {
di as err "impossible data"
error 498
}
di
forval win = `games'(-1)0 {
local tie = `points' - 3 * `win'
if `tie' <= `games' & `tie' > 0 {
di as txt "wins" as res %5.0f `win' ///
as txt " ties " as res %5.0f `tie'
}
else if `tie' == 0 di as txt "wins" as res %5.0f `win'
}
end
Nick
[email protected]
victor michael zammit
> > given a soccer (football) league,with seven teams and each
> team plays once
> > against the other six teams to complete one round ; the
> three possible
> > outcomes for any game is a win, a tie or a loss, ie three
> points , one point
> > or zero point ,respectively.Is it possible to write a
> program that could
> > give you the number of games the given team has won and /or
> tied and/or
> > lost , given that you know the number of games it has played and the
> number of points that it received ?
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/