EASy68K
http://easy68k.com/EASy68Kforum/

guess number
http://easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=1315
Page 1 of 1

Author:  death101 [ Fri May 02, 2014 5:15 pm ]
Post subject:  guess number

pls help me write this program:
first specify the number range, generates a random number from the range, the player then has to guess that random number, the program than indicates whether the correct answer, bigger or smaller. after correctly guessing the number, marks are awarded according to no of attempts and time taken to get the correct answer.

Author:  profkelly [ Fri May 02, 2014 5:59 pm ]
Post subject:  Re: guess number

We do not answer homework questions on this forum. That would defeat their entire purpose. Approach this as you would any programming assignment: create a flowchart or pseudocode representation of the program algorithm, code the program using clear well documented code, test, test, test, repeat as necessary.

Author:  death101 [ Wed May 07, 2014 2:45 pm ]
Post subject:  Re: guess number

i'm trying to modify your tutorial2 code, but i have no idea how to generate a random number for a specific range for example 50 to 140, is it possible??? please help me with this part.

Author:  profkelly [ Wed May 07, 2014 6:13 pm ]
Post subject:  Re: guess number

From Tutorial 2
Code:
* Generate random number for player to guess
* Uses timer as random number generator. This may not be the best way to
* generate a random number but it will work for this demonstration.
* Trap code 8 returns time in hundredths of a second since midnight in D1.L

    move.b  #8,d0
    trap    #15
    and.l   #$5FFFFF,d1     prevent overflow in divu
    divu    #100,d1         time count / 100
    swap    d1              swap upper and lower words of D1 to put remainder in low word
    addq.w  #1,d1           d1.w contains number from 1 to 100

The range of the random number is limited by the divu #100,d1 instruction. In the 68000, the divu instruction places the modulus in the upper word of the result. So, d1 = d1 modulo 100 limits the range of the numbers in d1 to 0 through 99. Adding 1 gives us numbers in the range 1 through 100.

If you want the limit to be 50 through 140 then take the number modulo 91 and then add 50. So:
Code:
    and.l   #$5FFFFF,d1     prevent overflow in divu
    divu    #91,d1          time count / 91
    swap    d1              swap upper and lower words of D1 to put remainder in low word
    addq.w  #50,d1          d1.w contains number from 50 through 140

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/