Current location: Hot Scripts Forums » Programming Languages » ASP » drop the lowest number


drop the lowest number

Reply
  #1 (permalink)  
Old 08-29-03, 06:47 PM
TheLaughingBandit TheLaughingBandit is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
drop the lowest number

i want to produce four random numbers between 1 and 6, drop the lowest number, then add the three remaining numbers.

example1
1, 3, 5, 6,
drop 1
total=14

example2
2, 2, 3, 5
drop 2
total=10

i am having truble figuring out how to drop the lowest. here is what i have written so far.

<%
Response.Buffer = True
randomize()
str1=Int(6 * rnd + 1)
str2=Int(6 * rnd + 1)
str3=Int(6 * rnd + 1)
str4=Int(6 * rnd + 1)

response.write("str1: <b>" & str1 & "</b><br>")
response.write("str2: <b>" & str2 & "</b><br>")
response.write("str3: <b>" & str3 & "</b><br>")
response.write("str4: <b>" & str4 & "</b><br>")
response.write("strtotal: <b>" & strtotal & "</b>")
%>
Reply With Quote
  #2 (permalink)  
Old 08-29-03, 08:38 PM
sequill's Avatar
sequill sequill is offline
Newbie Coder
 
Join Date: Jun 2003
Location: Alexandria, VA
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
There are probable a lots of different ways to do this. Here’s one.

Code:
<%
Randomize 
dim dice(3), minIndex, total, i
minIndex = 0
total    = 0

' Roll them bones
for roll = 0 to 3
    dice(roll)= Int(6 * rnd + 1)
    if dice(roll) < dice(minIndex) then minIndex = roll 
    total = total + dice(roll)
next
total = total - dice(minIndex)


'Display the results
for i = 0 to 3
    response.write( "Roll " & (i+1) & " = " &  dice(i) )
    if i = minIndex then response.write("*")
    response.write( "<br>")
next
response.write ("Total = " & total)
%>
Is there a simpler way?

In case you don't want to fire up your editor....
http://www.sequill.net/hotscripts/105/

Last edited by sequill; 08-29-03 at 08:40 PM.
Reply With Quote
  #3 (permalink)  
Old 08-30-03, 01:57 PM
TheLaughingBandit TheLaughingBandit is offline
Newbie Coder
 
Join Date: Aug 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
can this be done multiple time in one page?

i want to do this six times, saving the different totals as different variables, so that latter they can be put into six different places in a database.
here is your modified code.

<%
Response.Buffer = True
Randomize
dim dice(3), minIndex, total
minIndex = 0
total = 0
for roll = 0 to 3
dice(roll)= Int(6 * rnd + 1)
if dice(roll) < dice(minIndex) then minIndex = roll
total = total + dice(roll)
next
total = total - dice(minIndex)
%>
<html>
<head>
<title></title>
</head>
<body bgcolor="#FFFFFF" text="#FFFFFF">
<table width="255" cellspacing="0" cellpadding="0" border="2" bordercolor="000000">
<tr>
<td>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td <%if 0 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b>Roll 1</b></td>
<td <%if 1 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b>Roll 2</b></td>
<td <%if 2 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b>Roll 3</b></td>
<td <%if 3 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b>Roll 4</b></td>
<td bgcolor="0000FF" align="center"><b>Total</b></td>
</tr>
<tr>
<td bgcolor="000000" colspan="5" height="2"></td>
</tr>
<tr>
<td <%if 0 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b><%response.write(dice(0))%></b></td>
<td <%if 1 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b><%response.write(dice(1))%></b></td>
<td <%if 2 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b><%response.write(dice(2))%></b></td>
<td <%if 3 = minIndex then%>bgcolor="FF0000"<%else%>bgcolor="00FF00"<%en d if%> align="center"><b><%response.write(dice(3))%></b></td>
<td bgcolor="0000FF" align="center"><b><%response.write (total)%></b></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down with link perleo PHP 0 09-06-03 04:35 PM
Date drop down TheLaughingBandit ASP 0 08-25-03 01:39 PM
BUG - number of members surebetdmg HotScripts Site Bug Reports 2 08-10-03 04:35 PM
looking for a random number script ncben Script Requests 3 08-07-03 09:10 AM
auto number superman PHP 1 06-30-03 09:53 AM


All times are GMT -5. The time now is 03:23 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.