From: Kenichi Kamiya Date: 2012-02-04T12:20:20+09:00 Subject: Re: 4 random numbers take highest 3 and add them together. Hi, h4y4shi I think that error from some causes. * while # not closed(and not need) * when # when only in case * | # points different meanings, use "||" or "or" for this case below codes tested in 1.9.3p0 ex) stats1a = (rand(6) + 1) stats1b = (rand(6) + 1) stats1c = (rand(6) + 1) stats1d = (rand(6) + 1) gstats1a = 0 gstats1b = 0 gstats1c = 0 gstats1d = 0 if (stats1a>stats1b) || (stats1a>stats1c) || (stats1a>stats1d) gstats1a = stats1a end if (stats1b>stats1a) || (stats1b>stats1c) || (stats1b>stats1d) gstats1b = stats1b end if (stats1c>stats1b) || (stats1c>stats1a) || (stats1c>stats1d) gstats1c = stats1c end if (stats1d>stats1b) || (stats1d>stats1c) || (stats1d>stats1a) gstats1d = stats1d end mstr = gstats1a + gstats1b + gstats1c + gstats1d ex2) # another approach stats = 4.times.map{rand(6) + 1} min = stats.min p stats.reject{|n|n == min}.inject(:+) 2012/2/4 h4y4shi 13bladex : > I want to get 4 random numbers. The numbers will be between 1-6. I want > to disregard the smallest number and add the three biggest numbers > together. So far I wrote some ruby that I thought would do this but I > keep getting an error. > > statsrand = 0 > while statsrand == 0 > stats1a = (rand(6) + 1) > stats1b = (rand(6) + 1) > stats1c = (rand(6) + 1) > stats1d = (rand(6) + 1) > gstats1a = 0 > gstats1b = 0 > gstats1c = 0 > gstats1d = 0 > when (stats1a>stats1b) | (stats1a>stats1c) | (stats1a>stats1d) >  gstats1a = stats1a > when (stats1b>stats1a) | (stats1b>stats1c) | (stats1b>stats1d) >  gstats1b = stats1b > when (stats1c>stats1b) | (stats1c>stats1a) | (stats1c>stats1d) >  gstats1c = stats1c > when (stats1d>stats1b) | (stats1d>stats1c) | (stats1d>stats1a) >  gstats1d = stats1d > > mstr = gstats1a + gstats1b + gstats1c + gstats1d > > I cant find where the error is... > > -- > Posted via http://www.ruby-forum.com/. > -- Kenichi Kamiya