EASy68K  
It is currently Sun Apr 23, 2017 5:36 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: guess number
PostPosted: Fri May 02, 2014 5:15 pm 
Offline

Joined: Fri May 02, 2014 5:02 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: guess number
PostPosted: Fri May 02, 2014 5:59 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
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.

_________________
Prof. Kelly


Top
 Profile  
 
 Post subject: Re: guess number
PostPosted: Wed May 07, 2014 2:45 pm 
Offline

Joined: Fri May 02, 2014 5:02 pm
Posts: 2
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.


Top
 Profile  
 
 Post subject: Re: guess number
PostPosted: Wed May 07, 2014 6:13 pm 
Offline
User avatar

Joined: Thu Dec 16, 2004 6:42 pm
Posts: 1036
Location: Monroe County Community College, Monroe Michigan, U.S.A.
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

_________________
Prof. Kelly


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group