Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / how to add up randomly generated numbers

Author
Message
imtherealchaka
13
Years of Service
User Offline
Joined: 12th Oct 2012
Location:
Posted: 12th Oct 2012 20:57
so does anybody know how to add up randomly generated numbers

REM SCREEN DISPLAY
ink rgb (255,0,0),0 REM just inking red because red is my favorite color
cls 0 : center text 320,240,"Press 'q' to quit"
for x=1 to 9
REM this gives 9 values
print "Value #"+Str$ (x)+" = "+Str$(rnd(8)+1)
REM this gives you the statement and the random number
center text 320,200,"The sum of the first 8 numbers is ";
print REM just wondering what to put here
next x
print "Raise to the power of "+Str$ (rnd(9)+1)

sofuesh soclean
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 13th Oct 2012 00:00
You are adding strings to each other not numbers. First add the numbers before turning it into strings.

Andrew_Neale
16
Years of Service
User Offline
Joined: 3rd Nov 2009
Location: The Normandy SR-2
Posted: 13th Oct 2012 00:33
The random numbers aren't being stored at any point, so I have put the random value into a variable, added that variable to a running total and then displayed the random value from the variable rather than from the random function directly. Something like the below (additions to your code) might help.




Previously TEH_CODERER.

Login to post a reply

Server time is: 2026-07-07 17:32:08
Your offset time is: 2026-07-07 17:32:08